The magazine for Sinclair users
Sorc
meae
David Ahl, Founder and
Publisher of Creative Computing
You might think the term "creative com-
puting” is a contradiction. How can some-
thing as precise and logical as electronic
computing possibly be creative? We think
it сап be. Consider the way computers are
being used to create special effects in
movies—image generation, coloring and
computer-driven cameras and props. Oran
electronic "sketchpad'" for your home
computer that adds animation, coloring
and shading at your direction. How about a
computer simulation of an invasion of killer
bees with you trying to find a way of keep-
ing them under control?
Beyond Our Dreams
Computers are not creative per se. But
the way in which they are used can be
highly creative and imaginative. Five years
ago when Creative Computing magazine
first billed itself as "The number 1 maga-
zine of computer applications and soft-
ware, we had no idea how far that idea
would take us. Today, these applications
are becoming so broad, 50 all-
encompassing that the computer field will
soon include virtually everything!
In light of this generality, we take "appli-
cation to mean whatever сап be done with
computers, ought to be done with comput-
ers or might be done with computers. That
IS the meat of Creative Computing.
Alvin Toffler, author of Future Shock and
The Third Wave says, read Creative Com-
puting not only for information about how
to make the most of my own equipment but
to keep an eye on how the whole field is
emerging.
Creative Computing, the company as
well as the magazine, is uniquely light-
hearted but also seriously interested in all
aspects of computing. Ours is the maga-
zine of software, graphics, games and sim-
ulations for beginners and relaxing profes-
sionals. We try to present the new and im-
portant ideas of the field ina way that a 14-
year old or a Cobol programmer can under-
stand them. Things like text editing, social
A REMARKABLE MAGAZINE .
creative
Gorepatirg
“The beat covered by Creative Computing
is one of the most important, explosive and
fast-changing.” — Alvin Toffler
simulations, control of household devices,
animation and graphics, and communica-
tions networks.
Understandable Yet Challenging
Asthe premier magazine for beginners, it
is our solemn responsibility to make what
we publish comprehensible to the new-
comer. That does not mean easy; our
readers like to be challenged. It means
providing the reader who has no prepar-
ation with every possible means to seize
the subject matter and make it his own.
However, we don't want the experts in
our audience to be bored. So we try to
pubiish articles of interest to beginners and
experts at the same time. Ideally, we would
like every piece to have instructional or
informative content—and some depth —
even when communicated humorously or
playfully. Thus, our favorite kind of piece is
acessible to the beginner, theoretically
non-trivial, interesting on more than one
level, and perhaps even humorous.
David Gerrold of Star Trek fame says,
Creative Computing with its unpreten-
tious, down-to-earth lucidity encourages
the computer user to have fun. Creative
Computing makes it possible for me to
learn basic programming skills and use the
computer better than any other source.
Hard-hitting Evaluations
At Creative Computing we obtain new
computer systems, peripherals, and soft-
ware as soon as they are announced. We
put them through their paces in our Soft-
ware Development Center and also in the
environment for which they are intended —
home, business, laboratory, or school.
Our evaluations are unbiased and accur-
ate. We compared word processing printers
and found two losers among highly pro-
moted makes. Conversely, we found one
computer had far more than its advertised
capability. Of 16 educational packages.
only seven offered solid learning value.
When we say unbiased reviews we mean
it. More than once, our honesty has cost us
an advertiser—temporarily. But we feel
that our first obligation is to our readers and
that editorial excellence and integrity are
our highest goals.
Karl Zinn at the University of Michigan
feels we are meeting these goals when he
writes. "Creative Computing consistently
provides value in articles, product reviews
and systems comparisons ...in a magazine
that is fun to read."
Order Today
To order your subscription to Creative
Computing send payment to the appropri-
ate address below. Customers in the
continental U.S. may call toll-free to
charge a subscription to Visa, MasterCard
or American Express.
Canada and
Term | USA Foreign Surface Foreign Air
1year $20 $290r £12.50 %50о0г £21
2 years 637 $550r £24.00 $970r £ 41
З years $53 $800r £34.50 $1430r £61
We guarantee your satisfaction or we
. Will refund your entire subscription price.
Join over 80,000 subscribers like Ann
Lewin, Director of the Capital Children's
Museum who says, "| am very much im-
pressed with Creative Computing. It is
helping to demystify the computer. Its arti-
cles are helpfu!, humorous and humane.
The world needs Creative Computing."
creative
competing
Р.О. Box 789-М
Morristown, NJ 07960
Toll-free 800-631-8112
(In NJ 201-540-0445)
27 Andrew Close, Stoke Golding
Nuneaton CV13 6EL, England
Li
The magazine for Sinclair users
— | ша
November/December 1981
Volume 1, Number 6
DEPARTMENTS APPLICATIONS
2 LOIIUIB. „гоол ERREUR SRRERRLEEERERGs ERRARE 20 Experiments in Memory апа I/O Expansion. .. Sommers
Designing hardware
4 SYNC Мойіөв................................. Grosjean
26 An Inventory System......................... Justham
6 Kitchen SYNC............... Groupe, Tardiff, Zatkovich Keeping track of up to 150 items
Making the Most of What You've Got
GAMES
9 Сійсһоій2............................................
38 Натрвоп 5 РІапе. ........................... Hampson
1 0 Регсөрйіопв.................................. Ornstein The ZX80 answer to Rubik
Conversion: 4K ROM to 8K ROM and 8K ROM to 4K ROM
Artillery with Мойоп.......................... Dawson
You Аге in а Maze............................ McGath
The Hidden Chessmen...................... The Haars
Ug "T" Pozyski, Richardson Follow your shots
48 Нө5оигсөб........................................... 41
Finding the hidden way out
MACHINE LANGUAGE 42
14 An Introduction to Machine Language. ..........Logan Finding the pieces
Fourth in a series on machine language
Machine Language Teaches the
ZX80 to ВЕАР............................... Kennedy
Part 2 on READ and DATA
Create a Word Search Puzzle.................. McCray
Finding the hidden words
The Two Challenges of Taxman................. Brown
Can you beat the Taxman?
Staff
Publisher/Editor-in-Chief
Managing Editor
Associate Editor
Secretary
Production Manager
Art Director
Assistant Art Director
Typesetters
Financial Coordinator
Personnel and Finance
Customer Service
Order Processing
Circulation
MEMBER
David H. Ahl
Paul Grosjean
David Lubar
Elizabeth Magin
Laura MacKenzie
Susan Gendzwil
Diana Negri
Jean Ann Vokoun
Maureen Welsh
William L. Baumann
Patricia Kennelly
Ralph Lovery
Ruth Coles
Frances Miskovich
Carol Vita
Index to Advertisers
Blank Cassettes 37
Books for the Sinclair 15
Burnett Electronics 13
Byte-Back 5
Campbell Systems 41
Computer Cartoon Book 29
Computer Coin Games 43
Creative Computing subscriptions cover 2
D. Bruce Electronics 39
Richard Francis 40
Gladstone Electronics 11
Hardware Haven 41
Insight 39
J. Edmonds 28
JRS Software 7
Katie and the Computer 29
Lamo Lem 9
L.J.H. Enterprises 31
Sinclair Research 24, 25
Small Business Computers subscriptions
cover 4
Softsync 3
SYNC subscriptions 17
T-shirts cover 3
Zeta Software 31
Volume 1, Number 6
SYNC (USPS: 585-490; ISSN: 0279-5701) is published
bi-monthly for $16 per year by Creative Computing,
39 E. Hanover Ave., Morris Plains, NJ 07950. Second
class postage paid at Morris Plains, New Jersey
07950, and additional entry offices.
Subscription rates: USA: 6 issues $16; 12 issues
$30; 18 issues $42. Canada and foreign surface: 6
issues $20; 12 issues $39; 18 issues $56. UK air: 6
issues £13; 12 issues £25; 18 issues £36. Other air: 6
issues $31; 12 issues $60; 18 issues $87. Call (800)
631-8112 toll-free (in N.J. 201-540-0445) to begin
your subscription.
Postmaster: Send address changes to SYNC, P.O.
Box 789-M, Morristown, NJ 07960.
Copyright 1981 by Creative Computing. All rights
reserved. Reproduction prohibited in any form.
The Cover
The cover shows scenes from the first ZX Microfair
which was held in London in September. Photos
courtesy of Richard Gollner of Radala & Associates
in London.
November/December 1981
IELFEBTE
Thick Black Bars
Dear Editor:
Thick black bars on the display screen
may be caused by 60 Hz. A.C. hum resulting
from a failing capacitor in the power supply.
Cure is replacement. On my MicroAce
this involved breaking open the external
power supply case at the glue lines, and
replacing the large 1000 M.F.D. capacitor
with a new one. Be sure to observe the
polarity if you make this replacement.
Cecil Bridges
1248 N. Denver
Tulsa, OK 74106
Help Wanted
Dear Editor:
Do you think that a receive only teletype
program could be written into the 1K of
RAM or would it take more?. . .
Thanks for producing a fine magazine
for a pretty neat little computer.
James S. Johnson
Dear Editor:
I have had my ZX80 micro computer
for a few months now and I must say I am
very pleased with it. The only drawback
to the system is its limited RAM. I know
that a 16K RAM pack is available, but I
feel I do not need that much. I would be
satisfied with 2K or even 4K.
I am very familiar with electronics and
have done extensive breadboarding of
digital projects so I would like to see an
2
article showing a do-it-yourself memory
expansion with schematic diagram and all
the details.
Eric Bergstrom
3957 Denley, Apt. 108
Schiller Park, IL 60176
Dear Editor:
I have a Sinclair ZX80 with 8K ROM
and 16K RAM. Can you suggest where I
can get information on how to:
1) Use the ZX80 as a terminal with
coupler.
2) Decode and display Morse Code and
RTTY from shortwave (see QST magazine,
July 1981, p. 30).
3) Connect external inputs such as
switches or analog inputs to connector or
ear-jack.
4) Connect a printer (Is the ZX8l printer
available?).
5) Implement "slow" display mode.
Ronald Silver
2635 Cranston Rd.
Philadelphia, PA 19131
Ed. — Readers who have suggestions for
meeting the above requests are invited to
send their ideas to SYNC letters. The ZX
printer will not be available yet in the US
market although it is available in the UK.
Scrolling REM
Statements
Dear Editor:
When entering a machine language
program into a REM statement, you want
to scroll the REM off the screen. After
entering the Basic program, use the immedi-
ate instruction POKE 16403,A. A should
4K ROM
be the next Basic statement number after
the REM statement. Poking this puts
statement A at the top of the screen. I
have found this much easier than using
dummy statements, and I have not found
this technique suggested elsewhere.
Richard Van Workum
920 Leslie Ln.
Hanford, CA 93230
Cecil Bridges’ LED
Load Monitor
Dear Editor:
Cecil Bridges' article entitled "Adding
an LED Load Monitor to the ZX80” (SYNC
1:1) actually describes this useful hardware
modification for a MicroAce and not a
ZX80. If a schematic were available for
this modification to a ZX80, it would be
greatly appreciated since the MicroAce
diagram is useless to me.
Also, no part numbers are listed for the
Radio Shack LEDs that have been used
or at least their low current require-
ments.
Hopefully you can provide me with the
necessary information.
Cal Butler
81 Dorian Lane
Rochester, NY 14626
Ed. — David Ornstein points out that Cecil
Bridges' LED Load Monitor can be adapted
to work with the ZX80. Although the title
implied that the circuit was for use with a
2.Х80, the connection diagram given was
for the MicroAce, as Reader Butler cor-
rectly notes. To use the circuit with the
ZX80, connect the X wire as shown in
the article. The Y wire should be connected
to ground. A good place to tap ground is
Just below ІСІ?, on the large silver pad
on the printed circuit board.
SYNC Magazine
*
"THE BEST ACTION GAMES WE HAVE SEEN" SYNC MAGAZINE.
- SUPER INVASION. ·
AND WALL
ж
ear
BUS TERS .
. ` FOR YOUR 2X81!
* TOTALLY FLICKER FREE.
Absolutely no flicker. You don't need to press anything
for the display to move.
* AVAILABLE FOR THE ZX81 & ZX80
€ Ld
* MACHINE LANGUAGE
These programs are written in the computer's own
language making continuous, flicker-free action
possible for the first time.
* FITS 1K BASIC MACHINE.
Loads just like any other program on cassette. Each
Compatible with the ZX81 or the ZX80 with 8K ROM.
tape contains instructions on how best to load the
Also available for the ZX80 with 4K ROM.
cassette.
* ALL PROGRAMS ON CASSETTE.
Amazing as it is, these moving graphics programs fit
into your basic IK Sinclair!
* MOVING GRAPHICS
No hardware modifications required for these exciting
moving graphics games! A breakthrough for IK
computers.
SUPER INVASION
"The best Sinclair game to hit the market" -- SYNC Magazine.
SUPER INVASION is a flicker-free, moving graphics game with
three levels of play. SUPER INVASION challenges your skill as
you fire lasers at the attacking space invaders while
maneuvering your space craft to avoid their deadly lasers. 9
hen the winner emerges, the game automatically resets and P d
the battle begins again. $14. 95 ^
Ф
^
WALL BUSTERS
"A breakthrough in creating active display games" --SYNC ж РА
Magazine. WALL BUSTERS (formerly "Double Breakout") x Rw) dé /
challenges you to break through two barricades using nine balls S SS һы ji
and a curved bat. With seven levels of play, WALL BUSTERS is QN a l "à
hard to beat. You'll be amazed at the superb graphics in this ж” ра , d
IK game. $ 5% ж Р
/ P4
14.95 >
9 / /
Ф aS wj
November/December 1981
sync note
Paul Grosjean
ZX Microfair Report
September 26, 1981, was a great day
for many ZX80 and ZX81 users in the
UK. They braved the wind and rain to go
to the first ZX Microfair, held in Central
Hall, Westminster, London. The show was
a resounding success to the extent that
some people queued up to one hour to
get in. But once inside, the display of new
software and new products was well worth
the wait.
Quite a few new products caught my
attention. First of all, Quicksilva had a
Programmable Character Generator Board
which allows you to create your own
character set, either for output to the
television or to the ZX Printer. The board
would, therefore, allow an upper and lower
case set to be generated or a “Space
Invader” character to be formed. Also on
Quicksilva’s stand was their Sound Board
playing Bach in three-part harmony and a
full feature Defender program with sound
effects (if a Sound Board is connected,
that is).
Moving on, DCP Microdevelopments
has a prototype Voice Synthesizer Board
attached to a ZX81 through one of their
Peripheral Packs. The Voice Synthesizer
should be available in early 1982, but the
Peripheral Pack, containing 4K RAM and
an 8-Bit Input/Output Port, is available
now.
Technomatic had a demonstration of
some of the many uses for their low cost
I/O Port for the ZX80 and ZX81, including
music (well actually just a series of bleeps!)
and various external control functions.
Haven Hardware had their Program-
mable Character Generator on show and
a prototype of their Colour Board. The
Colour Board looks very impressive, but
is not available yet.
Lots of software cassettes were for sale,
ranging from Business Database packages
to arcade-game programs. There must have
been some fifty different software packages
and fifteen books about the ZX80 and
ZX81!
Sinclair had one of the new ZX Printers
at the Microfair, but no other product
news at the moment. The range of Sinclair
4
software was there for sale, as was the
ZX81 and 16K RAM Pack, but not the
ZX Printer.
SYNC was there, represented by Hazel
Gordon, Creative Computing's UK repre-
sentative. Altogether 32 exhibitors
crammed into the one hall, and, despite
the problem of large crowds, a fantastic
time was had by all who went.
Martin Wren-Hilton
UK Correspondent to SYNC
ZX81 Launched
in the U.S.
Sinclair Research Ltd., introduced the
ZX81 to the U.S. market on October 7,
1981, at a press conference in Boston,
Massachusetts. The ZX81 succeeds the
ZX80. Based on Sinclair's innovative four
chip design, the ZXS81 will be the least
expensive personal computer in the world.
It will retail in the U.S. at $149.95 assembled
and at $99.95 for the kit version. Mail
order sales will continue to be the main
means of distribution, but American
Express will also act as distributor.
Over 100,000 have been sold in Britain
since its introduction there in March 1981.
Sinclair expects the unit sales of the ZX81
to pass the unit sales of all other personal
computers by the end of 1981.
In the question period following the
announcement, Clive Sinclair emphasized
that the ZX81 is aimed at two main
potential buyers: the hobbyist and the
man on the street who wants to learn
about computers. Sinclair Research will
emphasize educational programs and
provide software. Software from others
will be encouraged. Asked about a disc
system, Sinclair noted that a British firm
is offering one already and that Sinclair
Research is working on its own model to
be available sometime next year.
The ZXS81 is described in Sinclair
Research's ad elsewhere in this issue of
SYNC, so we will not repeat that infor-
mation here. But three features that will
be of great interest to U.S. users are: a
switch allowing use on either channel 2
or 3, a builtin booster circuit for tape
loading, and an increased power supply
that will accommodate the 16K RAM.
Most impressive, however, was the
printer demonstrated along with the ZX81.
Unfortunately, it will not be available in
the American market for the immediate
future. A full sized sample of the printout
demonstrated is shown in Figure 1.
The World of Compukid
We have had a generation grow up not
knowing a world without radio, another
not knowing a world without TV, another
not knowing a world without computers.
Now we are watching another growing
which has not known a world without
personal home computers. When we look
at the world, we use the images and the
symbols we grew up on. This generation
will look at the world with “computer
eyes" and see things in new ways. We
want to capture something of what they
see and share it through the cartoon series
we are introducing in this issue of SYNC
“The World of Compukid [com-pu-kid].”
How will the “computer age kids” use the
computer symbols and language to describe
and interpret the world? The difference
between the compukid's picture and the
more conventional one should bring a
smile at least and hopefully a good laugh.
We invite you (especially our younger
readers) to submit ideas for our cartoonist.
Natural, real life incidents are the best,
but you do not need to limit your contri-
bution to those. Older readers may have
some fun by trying to see how the world
2-29
might look through *Compukid's" eyes.
Second ZX Microfair
to be Held
Mike Johnston, who organized the first
ZX Microfair held in September, has
announced that a second one will be
organized for January 30, 1982, again at
Central Hall Westminster, London.
Extended hours and doubled floor space
will take the second fair beyond the first.
Anticipating a larger show, Mike still hopes
"to keep the same informal and friendly
atmosphere" of the first. Mike can be
contacted at 71 Park Lane, Tottenham,
London, N17 OHG (Tel. after 7 p.m., 01
801 9172). "a
SYNC Magazine
= %
a ES
& z
a #
8 E
& E
E =
Е т
е ж
“a =
& ж
m
LE E
к жай
16 DIN Ctoddj
20 FOR Vel TO 64
30 LET Ctl) sSSet+SRBetSINn ((U-11j.
ЗәҰРТІ?»?
40 NEXT WU
ісе FOR G=1 ТО 64
110 PLOT G-1,C (G6)
115 МЕ G
XT
117 GOSUB 1000
oF
i28 Y"
125 GOSUS i000
130 LLIST
135 FOR H=1 TO 5
146 ІРБІМТ
145 NEAT R
1000 IF ІМКЕУ $4000 THEN RETURN
1212 GOTO 1000
Figure 1.
November/December 1981
CONTROL THINGS
WITH YOUR ZX80
4
A
Ф
$59
IN STOCK !
BYTE-BACK'S BB-1
CONTROL MODULE
=s 8 Independent Relays
“8 Independent TTL Inputs
The BB-1 CONTROL MODULE plugs directly
into the ZX80/1 expansion port. It
accepts inputs from remote switches,
thermostats, photocells, A/D's etc.
and under the command of a program in
the 2Х80/1 it can use the 8 relays to
control lights, motors, pumps, alarms,
recorders, water heaters, furnaces,
model railroads, 8 bit parallel port
printers and even remote data logging.
A comprehensive manual is included
that Пав complete software апа
application details. ( It runs in IK ) |
By using the BB-1 with your ZX80/1 to
control lights or other energy saving
devices you can get a TAX CREDIT based
on the cost of your ZX80/1 and your
BB-1 CONTROL MODULE. Details included.
ВВ-1 KIT + MANUAL............. $59 £50 |
ІВВ-1 WIRED 6 TESTED * MANUAL..$69 655
[BB-1 BLANK PC BOARD + MANUAL..$29 £15 |
i Shipping & Handling $3.00 l
l Order Phone 803-532-5812 |
Bill ту-П МІЅА-О Mastercharge
Exp. Date |
| Card No.
WE ACCEPT |
Name e ISA |
е MASTER CHARGE
| Address e CHECKS
City С М
State, Zip. LR | master charge
! BYTE-BACK Co.
Rt. 3. Box 147 е Brodie На» First Class (U.S.A.) |
Leesville, S.C. 29070 Air Mail (England)
l
C ee MRNA CON Papi сар J
ORDERS MAILED
4K ROM
IK RAM
Alan Groupe, Michael Tardiff, and Ivan Zatkovich
Making the Most
of What You ve Got
This month's column was inspired by
two other articles appearing in the May/
June issue of SYNC. In the first, David
Lubar told of his experiences in using the
NOT operator of Sinclair Basic. In the
second article, Bill Eckel introduced a
game called Black Hole and presented a
version which he "almost" got to fit in the
ZX80O's 1K available memory. These two
articles started us thinking, and we decided
that the Black Hole game might be the
perfect medium for demonstrating both
the usefulness of AND, OR, and NOT, as
well as a method for packing as much
possible into what might be considered a
"tiny" amount of memory.
But first, a short discourse on logical
operations.
As you have heard over and over again,
computers only understand "ones and
zeros." While this is true, a computer's
life is not quite that dull. Since you cannot
do much with just О and 1, bunches of 0’s
and Г5 (called bits) are grouped together
into larger sets, the most common of which
are bytes.
The normal arithmetic operators you
are accustomed to (+,-,*,/) take integers
(which in the 7Х80 are represented as
groups of 16 bits) and add, subtract,
multiply, or divide them as numbers.
Likewise, AND, OR, and NOT take integers
and combine them in various ways. In the
instance of these operators (called logical,
or Boolean, operators), however, it is more |
useful to think of the integer as the group
of 16 individual bits rather than as a
whole.
The operation "A AND B” is the col-
lection of 16 bits that are the result of
6
each bit of A "ANDed" with each bit of
B. These logical operators are often shown
in the form of tables as follows:
АМО 10 1 ORIO 1
он — lEe———.
010 0 010 1
110 1 D!1 1
NOT |
011
110
As you can see, AND returns а 1 when
both bits are 1; OR returns a 1 when
either bit is equal to 1. NOT inverts the
bit value (returns 1 if given 0, 0 if given 1).
There is one more Boolean operator
you should know about, called the EXCLU-
SIVE OR, or XOR for short. Here is what
it looks like:
While OR returns a 1 if either or both
bits are 1, XOR returns a 1 only if either.
but not both, are 1. In other words, XOR
returns a 1 if the bits are different. While
XOR is not in Sinclair Basic, it can easily
be coded as:
(A OR B) AND NOT (A AND B)
Groups of bits are combined to create
larger values much the same way as decimal
digits are combined in base 10. In base
10, the digit positions represent increasing
powers of 10 from right to left (1, 10, 100,
ЕНЕГГІЕГІ Sunc
and so on). The value of the number is
the sum of the digit values. Therefore,
“24” represents 2 tens and 4 ones, added
together, which is 24.
Binary works the same way. Bit positions
represent increasing powers of 2 from
right to left (1, 2, 4, 8, 16, etc.). Hence,
“11000” represents 1 sixteen, 1 eight, and
no fours, twos, or ones. Adding these
together, we also end up with 24.
Specific bits can be turned on or off
using the AND and OR operators of Sinclair
Basic. To turn a bit on in an integer, you
can "OR" it with a word that has just that
bit (or bits) turned on. To turn a bit off,
"AND" the word with one in which every
bit except the one you want is turned on.
To see how all this works, try the test
program in Listing 1. It asks for two
numbers, A and B. Enter these in decimal
(as normal numbers). You should keep
running the program until you have some
understanding of what is going on.
The main program itself is rather simple.
The subroutine at line 1000 probably
deserves some discussion, though.
Lines 1000-1010 test the leftmost bit
(the sign bit, which indicates if the integer
is a positive or a negative number) and
print out a 0 or 1 depending on that bit's
value. The remaining bits can be tested
by bit position, using a loop that steps
from 14 down to zero. (The leftmost bit
could not be tested in this loop because
of the way the Sinclair handles numeric
overflow.) Lines 1020-1030 and 1060-1070
set up a FOR-NEXT loop that counts
down from 14 to 0. Lines 1040-1050 test
the single bit 2**Y 1 (Y1 going from 14 to
0 — 2**0 — 1)
SYNC Magazine
JRS SOFTWARE
19 WAYSIDE AVENUE, WORTHING, SUSSEX, BN13 3JU
TELEPHONE WORTHING 65691 (Evenings and Weekends only)
ZX80 - PROGRAMMABLE MOVING DISPLAY
(4K-ROM only)
Yes! This really is a genuine moving display, not
another pause routine. If you want moving, flicker |
T— free displays land who doesn’t] then this is the
‘| Shoot the Invaders’ program for you. The secret lies in the ZX80's ability
ЕЕ БЕНЕН to keep the display on your screen without the need
to use all of the time available to it. Normally the
ZX80 would be doing nothing during this spare time
but the programmable moving display cleverly
interupts to process your own instructions written in the simple but highly
effective JRS numeric code. Great care has been taken so that the processing of
your codes can always be interupted to return to the display routine at the
precise microsecond that is required to ensure that your T.V. picture remains
completely rock-steady.
Normally a true moving display on a ZX80 would take weeks to write and you
would need to be an expert at machine-code programming. Now, at last, this
program offers you the ability to write your own true moving displays in under an
hour with no maching-code experience required whatsoever.
Cassette with 1k, 2k versions and 3 example programs plus FULL documentation
£4.95
зе
2Х81 - SLALOM (16K RAM PACK REQD.)
e
Uu slalom events always draw great crowds to the ski
i / / FJ LL ax P ! resorts and the T.V. cameras are never far behind.
Now the skier on your T.V. screen is directly under
your control and his success in negotiating the
slalom posts and achieving a fast time relies entirely
on your skill with the ZX81 keys.
Cassette and instructions £2.95
ZX81 - BLACK HOLES (16K RAM PACK REOD.)
Your starship is in an unknown galaxy consisting
entirely of black holes which continually threaten to
swallow you. Your skill at the controls and your
ability to look and think many moves ahead is the
only thing that stands between you and destruction.
How long can you survive!
Cassette and instructions £2.95
SPECIAL OFFER SLALOM and BLACK HOLES on one cassette for only £4. 50
OVERSEAS CUSTOMERS Payment must be made in Sterling by International Money Order (available
PLEASE NOTE at your bank) Please add 50 pence to cover overseas postage.
As you can see, AND can also be used
to test specific bits. If you "AND" the
integer you want to test with another in
which only the bits you want to test are
equal to 1 (called a *mask" by programming
types) the integer you end up with will be
zero if none of the tested bits were set,
and non-zero if any were. The resulting
integer will have a 1 in each bit position
that was equal to 1 in both the tested
integer and the mask.
Now, back to Black Hole. If you
remember, the problem was that the
program still did not fit into a 1K Sinclair,
which kept most Sinclair owners from
playing the game. Not being very happy
about being deprived of some fun with
our ZX80s, we tried to do something about
that.
Let us take a good look at the game
itself. The game board, called the "galaxy,"
has nine positions, each of which can be
either a "star" or a "black hole." The
Listing 1.
10 PRINT "ENTER A"
20 INPUT А
30 PRINT "ENTER В"
40 INPUT B
50 CLS
50 PRINT "A",
70 LET Z-A
80 GO SUB 1000
90 PRINT "B",
100 LET Z-B
11" GO SUB 1000
120 PRINT "##NOT A"
130 LET 7- NOT A
140 GO SUB 1000
150 PRINT "£NOT B",
150 LET 7- NOT В
170 GO SUB 1000
180 PRINT "A AND B",
190 LET 7-А AND B
200 GO SUB 1000
210 PRINT "A OR В",
220 LET Z=A OR B
230 GO SUB 1000
240 PRINT "A XOR В",
250 LET 7-(А OR B) AND NOT
(A AND B)
260 GO SUB 1000
270 PRINT
280 PRINT
290 GO TO 10
1000 IF 7<0 THEN PRINT "]";
1910 IF NOT Z<A THEN
PRINT "0";
1020 LET Yl1-14
1030 FOR Y-1 TO 15
1040 IF Z AND 2**y] THEN
PRINT "1";
1050 IF (Z AND 2**y1)-28
THEN PRINT "g";
1060 LET Ү1=Ү1-1
1070 NEXT Y
1080 PRINT "4";Z
1000 RETURN
=
most obvious way to store the galaxy is
with an array of nine integers, each
representing a position in the galaxy. Since
there are only 9 positions and since each
position can only be in one of two states
(star or hole), the entire galaxy can be
represented in a single integer, with 9 of
the bit positions representing the nine
positions in the galaxy. This type of
representation saves memory in two ways—
the game board itself takes less memory,
and, more importantly, the entire galaxy
can be updated all at once, rather than by
twiddling each position separately.
The representation we chose uses bits
1-9 (bit numbers go from 15 on the left to
0 on the right) to represent positions 1-9.
So the bit that represents the state of
position ‘n’ is 2**n. The remaining bits
are zeros. Since the initial state of the
board is all holes (0) with a star (1) in
position 5, we can set the whole galaxy to
the initial state with the statement LET
GALAXY —2**5 (line 10). Compare this
with lines 10-20 in the original program.
Lines 35-70 simply print out the galaxy.
Line 75 tests to see if the value of
GALAXY is 0. GALAXY being equal to
0 means that the collection of 16 bits that
represents the value of GALAXY 15 all
zeros. So GALAXY —0 means that each
position in the galaxy is a black hole — the
definition of losing.
Line 95 tests to see if the value of
GALA XY is 990. This value is represented
by a pattern of bits where bits 1, 2, 3, 4, 6,
7, 8, and 9 are 1’s and bit 5 along with the
unused bits (0 and 10-15) are zeros. You
can verify this with the binary calculator
above. This pattern is the definition of a
win.
Line 130 tests to see if the selected
position is valid. Since you can only shoot
at stars and not at black holes, the input
would be invalid, if the selected bit position
were a zero.
Lines 135 and 202-219 are the most
cryptic part of the program. Looking back
at Eckel's original Black Hole article, we
see that for each possible move, there is a
pattern of positions that must be inverted
(a star becomes a hole, a hole a star). If
the state of the galaxy can be represented
in a single integer, then certainly each of
these patterns can be too. Line 135 selects
the appropriate subroutine to set the value
of CHANGE to represent the required
pattern.
For example, if you look at the pattern
of positions that must be inverted if you
choose to shoot at star 5, you can see that
positions 2, 4, 5, 6, and 8 must be inverted.
The others must stay the same. This can
be represented by setting the corresponding
bit for each position that must be inverted.
Therefore, the required value (mask) would
have bits 2, 4, 5, 6, and 8 set with the
other bits cleared. This is what is done in
line 210. You can use the binary calculator
program to verify that 372 has the correct
pattern of zeros and ones.
While OR can be used to set certain
bits to ones and AND can be used to set
certain bits to zeros, XOR can be used to
invert certain bits without knowing their
original value. This is done in line 140.
As you can see, by carefully selecting
the representation of the data of your
program, you can squeeze more into— and
get more out of—the 1K memory of the
Sinclair.
10 LET GALAXYz2**5
15 CLS
20 PRINT "BLACK HOLE"
25 PRINT
30 PRINT
35 FOR І-0 TO 2
40 FOR 2-1 TO 3
45 IF (GALAXY AND (2**(3*
I-J)))20 THEN PRINT "OQ ";
50 IF GALAXY AND (2**(3*
I+J)) THEN PRINT "* ".
55 NEXT J
68 PRINT ,3*I-«1;" ";3*1I4+2;
" " 3*I-43
45 PRINT
70 NEXT I
75 IF NOT GALAXY-0 THEN СО
TO 95
8% PRINT "YOU BLEW IT"
85 PRINT "YOU ARE LOST IN
SPACE FOREVER"
90 STOP
95 IF NOT GALAXY-990 THEN
GO TO 115
100 PRINT "CONGRATULATIONS"
105 PRINT "YOU FOUND THE
BLACK HOLE"
110 STOP
115 PRINT "WHICH STAR?"
120 INPUT STAR
125 IF STAR«1 OR STAR»9 THEN
GO TO 120
130 IF (GALAXY AND 2**STAR)
-0 THEN GO TO 120
135 GO SUB 2*STAR4200
140 LET GALAXY-(GALAXY OR
CHANGE) AND NOT (GALAXY
AND CHANGE)
145 GO TO 15
202 LET CHANGE-54
203 RETURN
204 LET CHANGE-14
205 RETURN
206 LET СНАМСЕ-108
207 RETURN
208 LET CHANGE-146
209 RETURN
210 LET CHANGE-372
211 RETURN
212 LET CHANGE-524
213 RETURN
214 LET CHANGE-432
215 RETURN
216 LET СНАМСЕ-896
217 RETURN
218 LET СНАМСЕ-864
219 RETURN
SYNC Magazine
Py Y
- eg A
! d Ü LF > ]
/ % 2 4 N
Jj 7, gt. 717»; ^ 2
= = AM as \
I (3 OI ê | 4 j ў
е9 Уҹ
\ Y 40%
V. ee Ч А X
e »
/
т
леу
Widget (1:2, p. 23)
Author McGath writes: “Wait one widgeting minute! It is
not necessary to tinker with the economics of Widget to
make it winnable; just correct one typo: 600 should be
LET S=S+B*8
This vastly improves the return on small advertising outlays
as was originally intended. The other tinkering can still be
done to vary the challenge of the game, but a conservative
strategy will result in steady growth. I hope the error in
Widget has not shaken anyone's confidence in the free market
too badly."
Looking inside the ZX80 (1:3, p. 16)
92 PRINT CHR$(X-28);* ”:
240 PRINT CHRS(X);
A Trick and a Graphic System (1:3, pp. 30-31)
Author Comer calls attention to the continual problem of
making a distinction between zero and the letter O. Since this
is not clear in the listing, he suggests: "In order to get the
examples to run all one need realize is that everything is an
Oh. The only exception is in the example called the 'U.S.
Map. At the end of the second line the data should be
"eleven Oh twelve." Otherwise the map data is correct, but
pay close attention to the zeros (which are narrow) and the
Ohs (which are wider)."
Perceptions (1:5, p. 11, col. 2)
4th line from bottom: R2 should be R322.
Gra t PIX (1:4, p. 16, listing 5)
Add:
9010 REM ENTER FROM POL YGON/SEGM
ENT/ARC
Correct:
9920 IF P2»2*xPI THEN LET Р2-Р2-2
*PISINT (P2/(2*PI))
9925 IF T2>2*PI THEN LET T2-T2-2
Hangman (1:4, p. 40)
340 Be sure to use zero after G
430 PRINT CHR$(CODE(C$)):“#”:
————————————————""X— a a a
THE ZX80 BOOKSHELF LIBRARY OF CASSETTES
This attractive bookshelf folder (blue vinyl exterior, black interior)
contains a library of six Lamo-Lem 4K ROM cassettes, each held
firmly within a slot in the folder. Cassettes snap in and out with fin-
ger pressure. Тһе 974 by 97/4 Ьу 34 folder stores your library of
cassettes easily and compactly on a bookshelf. It includes the fol-
lowing cassette packages:
THE ZX80 HOME COMPUTER PACKAGE
Etch-A-Screen
Electronic Billboard
Composer
Calculator
Checkbook Balancer
THE CHEST OF CLASSICS
Lunar Lander
K-Trek
Life
Mindmaster
A NIGHT IN LAS VEGAS
Blackjack "Su
Roulette "азса!
Сгарв
Slot machine
THE ZX80 BOOKSHELF CASSETTE LIBRARY — Six cassettes of
computer programs in a bookshelf folder with dozens of manuals,
THE ZX80 BUSINESS PACKAGE
Search & Save
VideoComp-4
VideoGraph
ZX80 1K DISASSEMBLER
Disassembler Program
Memory Test
SUPER Z
(Adds 7 new BASIC statements)
The Super Z Program
A Super Z Module
A Super Z Demonstration
$59.95
reference cards , and full-color keyboard overlays. Also, many addi-
tional sheets, forms, and accessories, including a pad of coding
sheets. For all 4K ROM ZX80 and MicroAce computers ....................
postpaid.
LAMO-LEM LABS, СОрЕ206 BOX 2382, LA JOLLA, CA 92038
November/December 1981
4K ROM
8K ROM
risrcmEBrHrmrm
David Ornstein
Conversions: 4K ROM
to 8K ROM and
8K ROM to 4K ROM
One of the big questions raised by
Sinclair users is how to convert programs
from the 4K ROM to the 8K ROM and
vice versa. This article will serve as a
comprehensive guide to such attempts.
Let’s begin by a review of each of the
commands and functions of both ROMs.
It should be noted in the interim that
there is no guarantee that all programs
can be converted from one ROM to the
other. It should also be noted that, barring
an extremely complex software scheme,
there is no way to load a 4K program
from tape into an 8K machine or 8K
programs on tape into a 4K machine.
Expressions
An expression is a series of values, strung
together with operands, for example, 3-
4+8/AMD. Expression evaluation is
carried out by applying operators to their
operand(s). For example, applying the +
operator to the operands 4 and 26 yields
the value of 30. Expressions are evaluated,
operator by operator, according to the
priorities of the operators they contain.
The priorities for operators are shown in
Figure 1.
As you can see, the only difference
between the ROMs is the priority of the /
(division) operator. In theory, this could
cause problems. In practice, however, one
can usually be assured that an expression
specified on one machine, can be trans-
ferred as is, without ill effects. If you do
find this difference to be a problem, you
can always use parentheses to alter the
order of evaluation.
10
Functions
Many functions previously unavailable
to the 4K ROM user are now available
for owners with the 8K floating-point ROM.
The primary problem with converting
programs from 8K to 4K is that there is
simply no way to work with floating-point
numbers (that is, a number like 4.827736,
as opposed to an integer like 6 or 327), on
the 4K machine. Many of the new functions
are “floating-point functions.” For example,
there is no purpose in having a PI function
on an integer-Basic machine, as the value
3 is not as useful as 3.14159265.... The
following functions fall under this category
of “floating-point only”:
ACS(x) Arc Cosine
ASN(x) Arc Sine
ATN(x) Arc Tangent
COS(x) Cosine
EXP(x) Natural logarithm (base e)
PI The value 3.14159265
LN (x) Natural logarithm
SIN(x) Sine
SOR(x) Square root
TAN(x) Tangent
INT(x) Integer
Many other functions, however, are
worth the conversion process. These are
detailed below.
CHRS(x)
CODE(xS)
These functions perform the operation
of converting a number to its corresponding
character, and vice versa. They work
identically on both ROMs, but it must be
emphasized that the character sets on the
two ROMs are different. For example,
CHR$(20) yields a multiplication sign on
a 4K ROM, but on an 8K ROM it produces
an equals sign. You must not assume that
a line such as:
3100 IF CODE(A$)=13 THEN GOTO
100
can be directly transferred to the other
ROM. Most of the character set, primarily
the most important and most commonly
used sections, are the same on both ROMs.
The characters for numbers and letters
have the same codes, but this is not true
of all characters. The primary rule is: //
you are not sure, check it.
RND
RND(x)
The random number generation func-
tions differ simply in that the 4K returns a
random integer and the 8K a random
floating point number. The 4K random
number function, when called, spews up
a random integer between | and x, x being
the argument of the call, i.e., J=>RND(x).
The 8K function RND(no argument)
returns an FP (floating-point) value between
0 and 1. It is clearly a fruitless venture to
attempt to simulate the 8K function on a
4K machine, as you cannot have a floating
point number in an integer Basic program.
(A number between 0 and 1 must,
obviously, be an FP number.)
8K ROM 4K ROM
Operator priority | priority
Substrings 12 —
All functions
(except unary
minus and NOT)
жж
ка -
O =
E
©
Unary Minus
*
f a
--
- (binary)
=< >
d >= a>
NOT
AND
OR
NO whoo 0 DH оо о WH
Figure 1.
SYNC Magazine
Make the most of your
Sinclair Computer . . .
Software
on Cassette!
MULTIFILE Data Storage
System An amazingly versatile
multi-purpose filing system for the
16K ZX81. The program is menu-
driven, and number, size and
headings of files are user-definable.
Both string and numerical files are
catered for. Files may be created,
modified, replaced, and searched,
and are protected by an ingenious
foolproof security system. Output to
the ZX printer is also provided.
The program comes on cassette,
together with three quality data
cassettes for file storage, and com-
prehensive documentation, describ-
ing a host of applications for both
business and personal use. If your
ZX81 is bored with playing games,
then this program will give it plenty to
think about! . .$29.95 ($39.95 in Canada)
ZXAS MACHINE CODE
ASSEMBLER Bored with BASIC?
POKEING not your scene? Learn and
program in machine code the easy
way with this powrful Z80 assembler,
commissioned specially for the ZX81
& ZX80.
Standard 280 nemonics are simply
written into REM statements within
your BASIC program. The assembly
listings, together with addresses and
assembled codes are displayed on
the screen when assembled. The
assembled code is executed with the
USR function. The program uses 5K
of memory and is protected from
overwriting. Full documentation, in-
cluding examples, is supplied with
the cassette. This program is a must
for all serious ZX81 & ZX80 users. ...
$9.95 ($12.95 in Canada)
Last Minute Addition: ZXDB
The perfect complement to ZXAS
assembler, ZXDB is a complete combined
machine code disassembler and debugging
program. May be used in conjunction with
ZXAS and will leave about 9K of memory for
your own program. Additional features in-
clude Single Step, Block, Search, Transfer
and Fill, Hex Loader, Register Display and
more. Executed by single keyboard entry.
The combination of ZXAS/ZXDB plus one of
our books will teach you all you need to
know to program in machine codes.
ZXDB .. $9.95 ($12.95 in Canada)
Exciting
BookTitles!
MACHINE LANGUAGE MADE
SIMPLE FOR ZX80 and ZX81. A
complete beginners quide to machine
language programming. Go beyond
BASIC and open new computer
horizons! Finally find out what PEEK
and POKE is all about. Machine
language program enables more com-
puting power in less space, faster
running programs. The 120 pages of
this book are packed with programm-
ing techniques, hints and tips; useful
BASIC program to edit machine
language; numerous sample routines;
easy-to-use reference tables. .
$19.95($23.95 in Canada)
UNDERSTANDING YOUR
SINCLAIR ROM. А more advanc-
ed publication explaining the various
ROM features.$19.95 ($23.95 in Canada)
ZX
CHESS!
(for ZX81 and
8K/ZX80
both with
16K RAM)
A challenging chess programme, written in machine
language, designed to operate in the ZX81 fast mode. ZX
Chess allows you to select from 6 levels of play, choose
either black or white, and enables castling and en passant
moves. Unique ‘‘self-running” feature: you start the tape
and when the chess board appears on the screen, start
your game
ZX CHESS! Melbourne House. $24.95 (29.95 in Canada)
‘Mail Orders to: |
|
GLADSTONE- |
Мате
Address
City
Charge to O Visa
State
O MasterCard
Zip e
Card No.
Expiry
L] Check O Money order (Sorry, no CODs)
Amount enclosed
Full replacement warranty all tapes.
901 Fuhrmann Blvd., Buffalo, NY 14203. (in Canada, mail to
ELECTRONICS Gladstone Electronics, 1736 Avenue Rd., Toronto, Ont M5M 3Y7)
- Please send
Quantity
The ZX81 Pocket Book
Written in the informative and clear style of the earlier,
highly successful ZX80 Pocket Book, but with all new
content. This is the ideal follow-up to the Sinclair manual,
with application to both ZX81 and 8K ROM ZX80! The
ZX81 Pocket Book begins with an exceptional 1K RAM
programme (Pinning the Tail on the Donkey), which is
followed by revealing chapters on String-Functions and
Efficient Programming. Throughout there is a balance
between serious computing concepts and fun programs.
A particular emphasis is placed on the use of subroutines.
Ohter chapters provide Hints 'n' Tips, Decimal Justification,
Using Machine Code, Numeric Conversion, and ZX81
Adventure. Programs for both 1K and 16K machines
include: Ski Run, Ball & Bucket, Etch-a-Sketch, Digital
Clock, Standard Deviation, Dice Simulation, City of Alzan
(a long adventure program), plus many others. The book
contains 5 appendices containing ZX80 and ZX81 con-
versions, ZX81 module selector listing, solutions to prob-
lems in the book, ZX81 Basic command summary, and
error code summary. The emphasis throughout is on a
programming style designed to conserve memory, and
demonstrate practical techniques to make your programs
function better. Every Sinclair owner should have a copy
right alongside his manual!
The ZX81 Pocket Book. by Trevor Toms, Phipps Associates.
136 pages. Spiral bound. $11.95($14.95 in Canada)
NOT ONLY 30 PROGRAMS FOR
THE SINCLAIR 7Х81 BUT
ALSO ... detailed explanations and
much much more. All programs
designed to fit into the 1K memory of
the ZX81. Includes such favorites as
біаг Wars, Lunar Lander, Blackjack,
Mini Adventure. Also explanations of
how programs were written, hints on
how to write your own exciting pro-
grams, space-saving techniques,
peeks and pokes and other “сот-
plicated” functions. .........
$14.95($16.95 in Canada)
Description
| CASSETTES
Multifile -Data Storage
System
ZXAS - Assembler
| ZXDB - Disassembler/debugger
ZX CHESS! == ] —
BOOKS
Machine Language Made Simple
for ZX80 & ZX81
Understanding Sinclair ROM
The ZX81 Pocket Book
...Not Only 30 Programs for
Sinclair 2Х81...
Shipping charge, all orders
f Price each
$29.95 ($39.95 Cdn)
$9.95 ($12.95 Cdn)
$9.95 ($12.95 Cdn)
$24.95 ($29.95 Cdn)
$19.95 ($23.95 Cdn)
_ $19.95 ($23.95 Cdn)
511.95 ($14.95 Cdn)
$14.95 ($16.95 Cdn)
$1.50
It is, however, possible to obtain a
random integer on an FP machine. To
get a random number between 0 and x-1,
use the expression INT(RND*x)+ 1. Com-
pare the sample lines below:
4K Integer Basic
100 J+ RND(100)
110 REM set J equal to a random
120 REM number between 1 and 100
SK FP Basic
100 J=INT(RND*100)+1
110 REM set J equal to a random
120 REM number between 1 and 100
INKEYS
The INKEYS function is available only
on the 8K ROM. Without a moderate
amount of machine language programming,
there is no way to simulate it on the 4K
machine. If the thought of such an
endeavor strikes you as an interesting
project, I would suggest my article on the
ZX80's keyboard system (SYNC 1:2) asa
good starting point.
LEN(xS)
This function is not available on the 4K
machine, but it is easy to simulate by a
simple subroutine. On a 4K machine you
would add this subroutine at the end of
your main program. Then to find the length,
in bytes (characters) of a string you can
set a few argument variables and call the
subroutine. This process is illustrated in
Figure 2. The Len subroutine is found in
Figure 3.
SGN(x)
The SGN(x) function is used to
determine the sign (not sine) of a given
number, its argument. If the value passed
to the SGN(x) (often pronounced ’signum’)
function, is negative, the function returns
a value of -1. If the value passed is 0, the
function returns a zero. If the value passed
is positive, that is, greater than zero, the
signum function returns the value -1. For
example, if you PRINT SGN(-237) the
computer will dislay a -1 on the screen.
Whereas, were you to PRINT SGN(237),
the computer would place a 1 on the
screen.
This is a useful function. It is not quite
so useful, however, if you have to use a
subroutine call to access it. To elucidate,
you lose much of the value of being able
to specify an expression as
100 LET X-SGN(RES23/2) - USR(AD)*
4+1
when you must express it as:
100 LET ТЕМР-КЕ523/2
110 GOSUB 9000
120 LET X=TEMP+USR(AD)*4+1
ТЕ
9000 КЕМІЕМ
THIS SUBROUTINE FINDS
9010 REM THE LENGTH OF A STRING.
TO USE IT, SET Z$=x$; x$
9020 REM BEING THE STRING YOU
WANT TO FIND THE
9030 REMLENGTH OF. THE SUB-
ROUTINE WILL RETURN
9040 REM WITH THE LENGTH OF THE
STRING IN THE VARIABLE
9050 REMJ. YOU SHOULD BE SURE
THAT YOUR PROGRAM
9060 REM WILL RUN PROPERLY IF
THESE VARIABLES (Z$,J)
ARE DESTROYED.
9070 LET J=0
9080 IF 78-“” THEN RETURN
9090 LET J=J+1
9100 LET Z$-—TLS(Z$)
9110 GOTO 9080
Figure 2.
100 REM MAIN PROGRAM
110 LET H$=“LKJHGTYL”
120REM NOW CALL THELEN ROUTINE
130 LET Z$=H$
The listing of the routine to simulate
SGN(x) is given in Figure 4. The calling
procedure for the SGN(x) subroutine is
found in Figure 5. You may, however,
find it more useful (and easier) to find the
signum, directly in your program, as
opposed to calling it as a subroutine all
the time.
9000 КЕМ SGN
9010 REM THIS SUBROUTINE IS USED
9020 REM TO FIND THE SIGNUM OF
9030 REM A GIVEN NUMBER. TO USE
9040 REM IT, YOU PASS ITS ARGU-
9050 REM MENT IN THE VARIABLE
9060 REM TEMP. THE SUBROUTINE
9070 REM RETURNS THE SIGNUM OF
TEMP IN TEMP.
9080 IF TEMP=0 THEN GOTO 9200
9090 IF TEMP »0 THEN GOTO 9230
140 GOSUB 9000 9100 REM HERE IF TEMP « 0
150 PRINT J 9110 ТЕМР--1
160 REM THIS PROGRAM WILL 9120 RETURN
PRINT 9200 REM HERE IF ТЕМР-0
170 REM THE NUMBER 8, BECAUSE 9210 RETURN
Н5 9230 REM HERE IF ТЕМР>0
180 REM HAS 8 CHARACTERS IN IT. 9240 LET TEMP=1
190 STOP 9250 RETURN
Figure 3. Figure 4.
100 REM MAIN ROUTINE
|
|
|
|
500 LET TEMP=N
510 GOSUB 9000
5320 LET NEWVAL-— TEMP
9000 REM SGN
Figure 5.
! You now want the SGN(N)
!Call the subroutine
'Get the SGN into NEWVAL
!
! This sequence of code
! is equivalent to:
! LET NEWVAL=SGN(TEMP)
SYNC Magazine
VAL(xS)
The VAL(x$) function is used to convert
between a string containing the character
representation of a number to an actual
number. For example, PRINTing the
VAL(*1234^) yields the number 1234, not
the string “1234”. You cannot assign the
result of using the VAL() function to a
string, nor can you use a number as the
argument. That is, X$=VAL(TS) is illegal,
as is T=VAL(J). Once again, the 4K ROM
falls short by not providing this useful
function, but we can use the subroutine
in Figure 6 to simulate it. The subroutine
takes the argument T$ and returns the
VAL of it in the variable TEMP.
9000 REM VAL
9010 REM
9020 REM THIS SUBROUTINE IS USED
9030 REM TO FIND THE VAL(TS$). IT
9040 REM RETURNS THIS VALUE IN
9050 REM THE VARIABLE TEMP.
9060 LET ТЕМР=0
9070 IF T$=“” THEN RETURN
9080 LET TEMP=TEMP+CODE(T$)-28
9090 LET T$=TLS(TS)
9100 LET TEMP=TEMP*10
9110 GOTO 9070
Figure 6.
STRS(x)
This function is the inverse of the VAL()
function. It returns a string which corre-
sponds to the characters which would
appear on the screen if you were to PRINT
the number. For example, LETting T$=
STR$(23) would give the 2-character string
“22”, not the number 23. This function is
available on both the 4K and 8K ROMs,
and works identically on both. Therefore,
when translating from one ROM to the
other, you can use exactly the same
function without any problems.
USR(x)
The USR (pronounced ‘user‘) function
is used to call machine language subroutines
in the computer. The 4K and 8K versions
differ only in where they get the value to
return to Basic. The 8K version, when
your machine language subroutine
RETurns, yields the 16-bit number held
in the BC register-pair. The 4K version
returns the value in the HL register-pair.
(Do not worry if you do not understand
this; this is directed to machine language
programmers.)
ABS(x)
This function returns the absolute value
of its argument.This function is available
on each ROM and can be transferred
freely between 8K and 4K ROM pro-
grams.
PEEK(x)
The PEEK function is used to find the
value of an arbitrary byte of memory (1.е.,
byte x). It is available on both ROMs.
The only difference between the two is
that, whereas on the 4K ROM one might
бау:
J=PEEK(-13420)
on the 8K ROM one would say:
J=PEEK(46188).
The formulae for conversion between
ROMs are:
4K to 8K:
If the address is negative, make it positive
and add 32768.
8K to 4K:
If the address is greater than 32768,
subtract 32768 and make it negative.
NOT X
This function is used to obtain the logical
inverse of the value given as the argument.
It is available on both ROMs. The only
difference is that on the 4K ROM “True”
is represented as -1. Whereas on the 8K
ROM, “true” is represented by 1. Both
ROMs use 0 to represent “false.”
X AND Y/X OR Y
AND is available on both ROMs. It
does, however, work differently. On both
ROMs a statement such as:
IF A=12 OR В >37 AND X$—"Y" THEN
GOTO 1000
will execute identially on both ROMs.
But a statement such as:
JY=P AND 2+Z
will create different results on the two
ROMs.
On the 4K ROM AND (and OR) are
binary. That is, each bit of the operands
are ANDed (or ORed) together. On the
8K ROM the AND and OR operators
work differently. The expression AN AND
XZ will yield 0 if XZ is equal to 0.
Otherwise, it will return AN. Thus,
47 and 227
returns 227. But,
0 and 227
returns zero. OR works in a similar way.
X OR Y returns 1 if Y —0. Otherwise, it
returns X. The general rule for conversion
is: If the operators are used in a boolean
expression (like an IF statement), they
can be transferred directly. If not, you
are probably in trouble.(Ed. — See Kitchen
SYNC in this issue for further discussion
of AND, OR, and NOT.)
In the next issue, I will continue the
discussion of program conversion by giving
tips for converting commands (e.g., PRINT
and INPUT) from one ROM to the other.
Until next time, same relativistic time
period, same non-Euclidian universe. "a
You can help
this computer
Or
you canturn
J
the page.
ANNOUNCING ...
a
KEYBOARD BEEPER
FOR THE ZX80
This low power CMOS
circuit ends data entry
problems common to
Sinclair-style keyboards
by beeping when a key is
depressed. Fully
assembled and fits
inside computer.
SEND $12.00 TO
BURNETT ELECTRONICS
1729 Woodland Ave., #D
Palo Alto, СА 94303
4K ROM; IK RAM
8K ROM; IK RAM
How is it done?
An Introduction to Machine Code
Dr. lan Logan
The managing editor and I are frequently
asked about how one starts to use machine
code on a ZX80/1. So this article is an
attempt to reply to these questions, and I
trust that you will find that machine code
is not only for the expert.
An Outline View
The ZX80/1 microcomputer system as
supplied by Sinclair Research is capable
of being programmed in two different
languages, i.e., Basic and Machine Code.
Basic is a very easy language to use for
the beginner and, as long as one's programs
are simple, the language is almost ‘ideal.’
However, Basic is a rather ‘slow’ language
and limited in its commands.
Machine code, however, is a much more
difficult language to use. The resultant
programs are executed by the Z80 micro-
processor at a fantastic speed and the
complexity of the programs is limited more
by the knowledge of the programmer than
by the actual microcomputer.
It is always difficult to explain to the
‘beginner’ just how to write a machine
code program, but in this article we will
begin by drawing upon the similarities
between Basic and machine code.
Program Structure
A Basic program is made up of a set of
Basic lines. In the ZX80/1 system these
lines are kept in an area of the RAM
(random access memory) that is termed
by Sinclair as the PROGRAM AREA.
When the user first turns on the machine,
this PROGRAM AREA is empty, and the
user will then proceed to enter a program
into this area. The program can be as
short as a single line, e.g., 10 PRINT or
can be several hundred Basic lines. The
user will then RUN the program, and this
will result in the system interpreting line
after line of the program, as has been
determined by the programmer, until the
‘last’ line has been reached.
Ian Logan, 24 Nurses Lane, Skellingthorpe, Lincoln
LN6 OTT.
14
A machine code program is in many
ways dealt with in a similar manner. First,
the programmer must decide just what
part of the RAM he is going to designate
as his ‘machine code area.’ It is possible
in the ZX80/1 systems to choose an area
from several different parts of the RAM
but my favorite technique is to reserve
part of the PROGRAM AREA by using a
REM statement. The next task is to actually
enter the machine code into the RAM
and this has to be done by using POKE
commands. An actual machine code pro-
gram entered in this fashion can be made
up of just a single instruction or many
thousands of instructions. This program
is then ‘run’ by using a USR command
which is either a single line Basic program,
eB.
10 LET A=USR(16427)
or a USR command occurring in a longer
Basic program, in which case the machine
code program becomes a ‘machine code
subroutine' of the Basic program. Note
how the USR command has to be followed
by a number. This number is the address
of the location within the machine code
area where the machine code program
begins.
Instruction Format
All Basic lines can be described as
containing an obligatory 'operator' —the
command — and an optional ‘operand.’ The
line
10 PRINT
contains only the 'operator PRINT whereas
the line |
20 PRINT A
contains the 'operator PRINT and the
part that is to be printed, the ‘operand’ A.
Note how the Basic line has the ‘operator’
coming before the ‘operand.’
This division of a line into an ‘operator’
and an 'operand' is an essential part of
Basic syntax and the ZX80/1 systems with
their 'syntax checking' facility ensure that
the user has no difficulty remembering to
place his ‘operators’ before his
‘operands.’
Just as it is in Basic so it is in machine
code, but there are hundreds of different
‘operators,’ as opposed to the 20 or so in
Basic.
Whereas a Basic program is made up
of ‘decimal numbers and letters,’ a machine
code program consists of only a set of
numbers. These numbers can be considered
to be in binary, decimal or hexadecimal
arithmetic, but for users of the ZX80/1
systems the use of the decimal values is
the easiest method, although the ‘expert’
will usually only think in hexadecimal
arithmetic.
So what are the ‘operators’ in machine
code? Well, they are the decimal numbers
0-255, (hex. OO-FF), but since more than
256 'operators' are required, the numbers
203, 221, 237, and 253 (hex. CB, DD, ED,
and FD) introduce a second decimal
number into the 'operators.'
In Basic the 'operators' are commonly
called the ‘commands’ and in machine
code the 'operators' are called the 'instruc-
tions.’ Fortunately, one does not have to
memorize all the different numbers as
each instruction has been given a descrip-
tive 'mnemonic' and most programmers
only ‘look-up’ the numbers when they need
them.
The ‘operands’ in machine code аге
also numbers in the range decimal 0-255,
(hex. OO-FF), and these ‘operands’ аге
placed after the instructions proper when
they are needed.
A machine code program may also
SYNC Magazine
The ZX81 Companio
The ZX81 Companion by Bob Maunder follows the
same format as the popular ZX80 Companion. The book
assists ZX81 users in four application areas: graphics,
information retrieval, education and games. The book
includes scores of fully documented listings of short routines
as well as complete programs. For the serious user, the
book also includes a disassembled listing of the ZX81
ROM Monitor.
MUSE reviewed the book and said, "Bob Maunder’s
ZX80 Companion was rightly recognized to be one of the
best books published on progressive use of Sinclair's first
micro. This is likely to gain a similar reputation. In its 130
pages, his attempt to show meaningful uses of the machine
Is brilliantly successful."
"The book has four sections with the author exploring
in turn interactive graphics (gaming), information retrieval,
educational computing, and the ZX81 monitor. In each
case the exploration is thoughtfully written, detailed, and
illustrated with meaningful programs. The educational
section is the same — Bob Maunder is a teacher— and here
we find sensible ideas tips, warnings and programs too."
Softbound, 5 1/2 x 8", 132 pages, $8.95.
Getting Acquainted
With Your 7Х81
This book is aimed at helping the newcomer make most
effective use of his ZX81. As you work your way through
it, your program library will grow (more than 70 programs)
along with your understanding of Basic.
The book is chock full of games such as Checkers which
draws the entire board on the screen. Other games include
Alien Imploders. Blastermind. Moon Lander. Breakout.
Digital Clock, Roller-Ball. Derby Day. and Star Burst.
But the book is not all games. It describes the use of
PLOT and UNPLOT. SCROLL. arrays. TAB. PRINT AT.
INKEYS. random numbers and PEEK and POKE. Youll
find programs to print cascading sine waves. tables and
graphs; to solve quadratic equations; to sort data: to
compute interest and much more.
Softbound. 5 1/2 x 8”. 120 pages $8.95.
November/December 1981
The Gateway Guide
to the ZX81 and ZX80
The Gateway Guide to the ZX81 and ZX80 by Mark
Charlton contains more than 70 fully documented and
explained programs for the ZX81 (or 8K ZX80). The book
is a "doing book," rather than a reading one and the
author encourages the reader to try things out as he goes.
The book starts at a low level and assumes the ZX80 or
Z X81 is the reader's first computer. However by the end,
the reader will have become quite proficient.
The majority of programs in the books were written
deliberately to make them easily convertible from machine
to machine (ZX81, АК 7Х80 or ІК 7Х80) so no matter
which you have, you'll find many programs which you can
run right away.
The book describes each function and statement in
turn, illustrates it in a demonstration routine or program
and then combines it with previously discussed material.
Softbound, 5 1/2 x 8", 172 pages, $8.95.
Computers For Kids,
Sinclair Edition
Computers For Kids. by Sally Larsen is the fourth book
in this highly successful series. (Previous editions have
been released for TRS-80, Apple and Atari computers.)
Written expressly for youngsters ages 8 to 13. the book
requires no previous knowledge of algebra. variables or
computers. Armed with a ZX81 and this book, a child will
be able to write programs in less than an hour. A section is
included for parents and teachers.
The book starts with a patient explanation of how to use
the Sinclair, graduates to flow charts, and simple print
programs. The twelve easy-to-read chapters go through
loops, graphics and show other programming concepts.
and show in a painless way how to make the computer do
what you want.
Donald T. Piele, Professor of Mathematics at the University
of Wisconsin-Parkside says, “Computers For Kids is the
best material available for introducing students to their
new computer. It is a perfect tool for teachers who are
learning about computers and programming with their
students. Highly recommended.”
Softbound, 8 1/2 x 11", 56 pages. $3.95.
Order Today
To order any of these books, send payment plus $2.00
shipping and handling per order to Creative Computing
Press at the address below. Visa, MasterCard and American
Express orders should include card number and expiration
date. Charge card orders may be called in toll-free to the
number below.
creative competing
Toll-free 800-631-8112
In NJ 201-540-0445
39 E. Hanover Avenue
Morris Plains, NJ 07950
15
contain 'data.' Once again this will be in
the form of locations holding decimal
numbers in the range 0-255.
АП this is better illustrated by the
example in Figures 1 and 2.
Note that the machine code subroutine
would occupy 5 locations and would
be entered by:
50 POKE 16427,62
52 POKE 16428,1
54 POKE 16429,198
56 РОКЕ 16430,6
58 РОКЕ 16431,201
Comment
A Simple Basic Subroutine
10 LET Z=1
20 LET Z=Z+6
30 RETURN
‘operator’ is ‘LET Z’, ‘operand’ is ‘1’
‘operator’ is ‘LET Z’, ‘operand’ is ‘Z+6’
‘operator’ is ‘RETURN’.
Figure 1.
and ‘run’ by using:
60 LET A=USR(16427)
Note: Reserve 16427-16431 first (16514-
16518 for 8K).
Variables v. Registers
In a Basic program there are two
different ways of handling variables. The
first is to use ‘named variables,’ e.g.,
A,B,COUNTER, and this is very much
the standard method. However, there is
an alternate method that involves the use
of ordinary memory locations to which
the user will assign values as necessary.
This second technique is commonly used
in games that use the display file. E.g., if
location 16800 is a ‘certain point’ on the
screen, then ‘POKE 16800...’ will assign
the required value and ‘PEEK 16800’ will
collect the value of the variable.
A machine code program normally uses
this second method. That is, the program-
mer first selects certain locations that he
wishes to be filled with ‘named variables’;
however, these ‘names’ are only known to
the programmer and not the ‘computer.’
It is possible though to take the general
concept of the ‘Basic named variables’ a
little further and draw a useful analogy
between the use of certain Basic variables
and the internal registers of the Z80 micro-
processor.
In a Z80 microprocessor as used in the
ZX80/1 there are many 'registers.' These
registers can be considered as ‘named
variables’ in an internal ‘variable area.’
Each is equivalent to an ordinary memory
location in that it can hold a number
which has the decimal range 0-255 (hex.OO-
FF). The simple registers are the A, H, L,
B, C, D, and E registers. The full set of
registers is shown in Figure 2.
Although the registers are equivalent
to ‘one memory location,’ there are many
times when it is desirable to use a pair of
registers that would thereby have the
equivalent of ‘two locations in memory.’
The simplest register pairings are those
of the H and L registers, the B and C
registers and the D and E registers. Usually
these are written as HL,DE, and BC. Such
register pairs can be considered to be
able to hold numbers in the range decimal
0-65535 (hex. DOOO-FFFF).
16
The Machine Code Subroutine
mnemonic Decimal
LD A,+1
ADD A,+6
RET
Figure 2.
The registers of the Z80 can therefore
be considered as follows:
The A register is a variable named
‘A’.
The H register is a variable named
H’
and so on for all the simple registers named
above. The register pairs can be considered
as:
The HL register pair is a variable
named ‘HL’.
The BC register pair is a variable
named ‘BC’.
The DE register pair is a variable
named ‘DEP’.
Comment
Load the ‘A’ register with
the constant 1.
Add the constant 6 to the
value in the “А” register.
Return to the calling routine.
Actual Machine Code Instructions
Now that the analogy has been made, it
is possible to use the variables A, H, L, B,
C, D, E, HL, DE, and BC to explain the
more simple of the 600+ instructions of
the Z80 machine code language.
1) Loading Constants.
The simplest instructions are those that
are uSed to load a register or a register
pair with a ‘constant.’ For example, in the
instruction ‘LD A,+dd’, the actual code
would be two bytes. The first is a decimal
62, (hex.3E), and the second, the value of
the constant itself. This instruction can
The Registers of the Z80 Microprocessor
The simple registers.
Figure 3.
The more complicated registers.
SYNC Magazine
be considered to have the same result as
a Basic line:
БЕГІАЗ uos a constant,
when the variable A is located in the
microprocessor. In the instruction ‘LD
HL, dddd' the code is three bytes. The
first is decimal 33 (hex.21) and the following
two are the constant. Note that the constant
always appears with the 'remainder coming
before the integer of the 'constant/256.'
This instruction would be equivalent to:
LET HL - ... a constant.
or more precisely:
LET L = ‘remainder’ and
LET H = ‘constant/256’
2) Loading Registers from memory Loca-
tions
There are only two simple instructions
in this group. The first instruction is “LD
A,(addr.)’ which is a three byte instruction.
The first number is a decimal 58 (hex.3A)
and whose other two bytes are the 'address
in memory' of the location that is to be
copied. Note that the address is once again
to be entered as the ‘remainder’ followed
by the ‘address/256.’
Get ín
Sync
You and your friend are both new owners of
a Sinclair ZX80 or ZX81. You bought your
computers together and marveled over the
low price you had to pay for the Sinclairs
innovative design and sound performance. With
visions of becoming computer experts, each
of you read your manuals from cover to cover,
discovering together the elementary functions,
routines, and capabilities of your new systems.
Within no time you were both running your
computers with ease and confidence.
But soon your friend is expertly and efficiently
adapting new peripherals and software to the
machine —equipment that you didnt even know
existed. Every day your fellow Sinclair user is
showing you new and interesting programming
techniques, creating interesting graphics, chal-
lenging you to new games, and converting
programs from other computers to the Sinclair.
Before you know it, youre friend has far sur-
passed you in computer aptitude and 'know-
how." How did your friend get so far ahead of
you? The answer is simple.
November/December 1981
The Basic equivalent of this instruction
is:
LET A=PEEK (1st+2nd,*256)
The other instruction is for loading the
HL register pair, and the mnemonic is
‘LD HL, addr.). Again, this is a three
byte instruction. The first byte is decimal
42 (hex.2A), and the other two bytes are
the address again.
The Basic equivalent is:
LET HL=PEEK (1st +2nd*256)+256*
PEEK (1st 2nd*256)
or more simply:
LET L= PEEK (addr.)
and LET H=PEEK (addr. +1)
3) Three Further Instructions
It is beyond the scope of this article to
detail more than just a few of the instruc-
tions in the Z80 machine code instruction
set, but the following instructions will be
used in the game below.
a) The contents of most registers can
be copied into another register by using
the appropriate instruction.
E.g., the instruction ‘LD E,A’ copies
the contents of the A register into the E
register. The instruction code is decimal
95 (пех. ЭЕ).
Your friend reads ФҮМС-а Creative
Computing publication written solely for Sinclair
ZX80 and ZX81 users. SYNC takes you far
beyond the limits of theory and practice as
described in the manual. Every issue is packed
with articles, tutorials, how-to" material, reviews,
and evaluations that enable you to use your
Sinclair to its greatest potential. Hardware tips,
puzzles, problems, letter-to-the-editor—all the
information supplied in SYNC will keep you
up to date on new ways to do things with your
Sinclair that couldn t be done before.
SYNC functions on many levels with tutorials
for beginners and concepts that will keep the
pros coming back for more. We ll show you
how to duplicate commands available in other
Basics and we ll even show you how to do
things on the Sinclair that cant be done on
other machines.
While applications and software are the meat
of SYNC, we recognize that along with useful,
pragmatic applications, like financial analysis
and graphing, you want games that are chal-
The Basic equivalent would be:
LET E=A
b) The contents of the DE register pair
can be added to the contents of the HL
register pair by using the instruction ‘ADD
HL,DE. This instruction has the code
decimal 25 (hex.19).
The Basic equivalent would be:
LET HL=HL+DE
or if preferred:
LET L=L+E
and LET H=H+D+ carry if present.
c) The last instruction of any machine
code program must always act as a
‘RETURN.’ It is easy to understand that
this can be performed by the straightfor-
ward instruction ‘RET’ whose code is
decimal 201 (hex.C9), but it is often found
that the ‘return’ is made by using a ‘stack-
handling’ instruction instead.
The Basic equivalent of the “КЕТ”
instruction is simply:
RETURN
Once the reader has understood just
how instructions are used, it is fairly easy
to gradually use the more complex instruc-
lenging and fun. We give you complete listings
and sample runs of new games like Widget,
Gauntlet, Forest Treasure, and Life as well as
old favorites like Tic Tac Toe and Mastermind
with a computer twist. All can be picked up
from the pages of SYNC.
Order SYNC Today
To order your subscription to SYNC in
the USA, send $16 for one year (6 issues),
$30 for two years (12 issues), or $42 for
three years (18 issues). Send order and
payment to the address below or call our
toll-free number to charge your order to
your Mastercard, Visa, or American
Express.
Subscriptions in the UK are mailed by air
and cost £13 for one year, £25 for two years,
or £36 for three years. Send order and
payment to the UK address below.
Canada and other foreign surface subscrip-
tions cost $20 for one year, $39 for two
years, and $56 for three years (US dollars)
and should be sent to the USA address.
Subscribe to SYNC and get the most from
your Sinclair.
The magazine for Sincl
39 East Hanover Avenue
Morris Plains, NJ 07950, USA
Toll free 800-631-8112
(In NJ 201-540-0445)
27 Andrew Close
Stoke Golding
Nuneaton CV13 6EL, England
17
tions. Suitable lists and tables of all the
instructions are to be found in all books
on machine code programming, or if the
reader prefers he can just take notes on
'new' instructions as he finds them in
different programs.
The Demonstration Game
The following Basic program includes
many features that can be easily ‘machine
coded. However, as with many similar
programs, there is no genuine advantage
to replacing Basic lines with machine code
subroutines, except from the point of
interest.
If the reader wishes to try writing the
whole of a ‘Basic program’ in machine
code, then I very much suggest that he
use a ZX80 with the 8K ROM and a ‘slow
converter, or a ZX81, as machine code
programming in ‘slow’ mode is the easiest
for larger programs.
The Tower Game
There are two towers of 'bricks' and a
single brick is taken from one tower and
placed on the other tower. The choice of
the 'declining' tower is made at random.
The game is over when only a single tower
remains.
The Tower Game (4K ROM; IK RAM)
20 RANDOMISE
30 DIM L2) The
40 LET L£612-62 The
ЭО LET 2) =69
60 FOR A=1 TO 4
70 PRINT 79-65;"HBiHHHdHidbiHHudu" 12
go NEXT А
90 FOR &-i TO 4
100 PRINT 9-6; "НЕНА"
110 NEXT А
120 FRINT
130 PRINT
140 FOR G=RND (23) +4
30 PRINT "YOUR GUESS 14-27) ";
150 INFUT Y
170 IF Ys4 OR Ү>27 THEN GO TO 1
"*dHEGGGGGHRGGGGG "
180 PRINT "-4"siYs",HMINIE-4"i(G,"
PRESS N/L"
190 LET C-o
200 INFUT AS
210 LET R=RND (2)
| spaces, o shifted “G”
shifted
The computers guess.
Make
moves to eliminate a tower.
A suitable range.
60) actual
Watch the spacing!
The larger usable RAM and the compact
integer handling of the ZX80 with a 4K
ROM allows for a ‘more complicated’ game
than on a ZX80 with the 8K ROM ora
ZX81. Therefore, the 8K version is slightly
different overall but does use the identical
central algorithm.
A First Machine Code Subroutine
The easiest Basic line to convert to
machine code is the line:
4K: 230 LET A-—PEEK(16396) - PEEK
(16397*256
8K: 180 LET A=PEEK 16396+PEEK
16397%256
The Tower Game (8K КОМ; ІК RAM)
20 RAND
зо DIM L t2)
40 LET (1) =62
30 LET L (2)269
60 FOR А=1 TO 4
70 PRINT 9-8; "Ей" he
во NEXT A
90 FOR 6-1 TO 4
100 FRINT 576; "ЯДНА"
110 NEXT А
120 РКІМТ "ZHH77777WW77777"
150 LET C=0
140 PAUSE So
190 РОКЕ 16457,2525
160 LET RINT (CRND+1.5)
170 LET PzltiRzl1)
180 LET А=РЕЕЕ 16396+FEEK
(2G
190 FORE А+ К) о
200 LET ЦК) SL iR) +14
210 LET LF)-L(P)-—14
220 FOKE AtL(P),8
250 LET Сес+1
240 IF L(R)Zz118 THEN GOTO 140
230 PRINT "DID YOU GUESS#";C;"#
MOVES?"
FAST
16397
Cammnent.
Different each time.
two towers.
pointers to the tops of the
towers in the Display File.
Spaces.
The towers.
4 spaces, shifted
.2 Spaces,
"G" forms a base to the towers.
a guess for the number of
But not the
range.
Initialise the move counter
Wait for a NL,
Randomly choose а tower.
before each "move".
220 LET Pei-t(R=1) If Rl then F-Z, and vice versa.
ЭО LET A=FEER (145964) 4+FEEKR (14629 Fick up the start of the D-file.
7) X256
240 FOKE А+ Б), O
250 LET L(FOSL(R)*14
260 LET L(F)sLt(F)-14
270 POKE А+ (Е), 9
280 LET C=C+1
290 IF L(FOZ118 THEN GO TO 200 IF
500 PRINT "IT WASH "SC; 4MOVES A On
NDH”;
310 IF ABS(G-COZABS(O-U)
GO TO 340
Fut
THEN 0
AO PRINT "YOU WON” Well
o0 STOP
Зао PRINT "I WON” Ch
Remove a brick.
Point to
Foint to space above the other tower.
the brick
Count the
two towers ex
end message.
"new" top of tower.
into place.
"move."
ist, then go back.
Whose guess was the better?
done,
ASE
A GD.4
Initialise the move counter.
or 140 FOR D=1 TO 29
150 NEXT D
Randomly choose a tower.
If R1 then F=2,
Fick
"А",6 spaces, shifted "A"
Comment.
Different each time.
The two towers.
The pointers to the tops of the
towers in the Display File.
Spaces.
graphic A, 6 sp., grap. А.
g grap: "7", 2 ер., 5 ағара 7
SLOW
and vice verga.
up the start of the D-File.
Remove a brick.
Point to
Foint to space above the other
Fut the brick
Count the
If two towers ех
Did vou do well?
"new" top of tower.
tower.
into place.
"move."
ist, then go back.
which picks up the address of the start of
the Display File.
In the 4K program one proceeds as
follows:
1) Replace line 230 by:
230 LET A=USR(16427)
2) Enter a line 10
10 REM 1234
that reserves 4 locations for a machine
code routine. The address of the first of
these locations being 16427.
3) Remove line 10 from the listing by
using, for example:
LIST 250
and from now on do not use HOME or
LIST as this will cause problems. (The
problems can be solved by using after a
HOME, etc., Cursor down, cursor down
& POKE 16403,20 if needed)
4) Enter:
POKE 16427,42
POKE 16428,12
POKE 16429,64 (hex. 40)
POKE 16430,201 (hex. C9)
which will enter a 4-byte machine code
routine into the 4 reserved bytes of line
10.
The ‘mnemonics’ for this program are:
LD HL,(D-File)
RET
where the address of D-File is 16396 in
decimal, which splits into a remainder of
12, and 64*256.
(hex. 2A)
(hex. 0C)
SYNC Magazine
5) Run the program. The reason for
this routine working is that the expres-
sion:
USR(16427)
returns to the Basic program the current
value of the HL register pair.
In the 8K program one proceeds in a
similar manner.
1) Replace line 180 by:
180 LET A=USR 16514
2) Enter a line 10:
10 REM 123456
that reserves 6 locations for the machine
code. The starting address being 16514.
3) Enter:
POKE 16514,42 (hex. 2A)
POKE 16515,12 (hex. 0C)
POKE 16516,64 (һех. 40)
POKE 16517,68 (һех. 44)
POKE 16518,77 . (hex. 4D)
POKE 16519,201 (hex. C9)
which will enter a 6-byte machine code
routine into line 10.
4) RUN the program.
The ‘mnemonics’ for this program аге:
LD HL,(D-File)
LD B,H
where as before the address of D-File has
to be split into ‘12’ and ‘64’.
The two new instructions ‘LD В.Н
and LD C,L’ are needed as the SK ROM
returns the value of the BC register pair
rather than the HL register pair.
A Second Machine Code Routine
If you have followed the article so far,
you might now like to try a longer machine
code routine. Several new instructions will
be introduced.
In the Tower Game the start of the
Display File is used as a base address to
which the variables L(R) and L(P) are
added in turn. The resultant address then
points to the location that is to be filled
with a specific value. All of this procedure
can be easily performed in machine code.
In the 4K program one proceeds as
follows:
1) Replace lines 230 and 240 by:
230 POKE 16431,L(R)
which transfers the current value of L(R)
to a suitable location for the machine
code routine and
240 LET A=USR(16427)
which runs the machine code routine.
Note how the variable A is just a dummy
variable, i.e., not used later.
2) Replace line 270 by:
270 POKE 16441,L(P) and
275 LET A=USR(16437)
3) Replace line 10 by:
10 REM 12345678901234567890
4) And fill line 10 by using a loader
such as:
500 FOR A=16427 TO 16446
510 INPUT B
520 POKE A,B
530 NEXT A
RUN 500
November/December 1981
and enter the code:
42,12,64,17,0,0,25,54,0,201,42,12,64,17,0,
0,25,54,9,201
5) Now delete the loader in lines 500-
530 and RUN the whole program.
The machine code routine is given in
Figure 4.
1642710 HL,(D-File) Pick-up D-File.
3) Delete lines 500-530 and RUN the
program.
The reader is now encouraged to try
his own hand. For example, the variable
C can be replaced entirely. This will,
however, probably require the use the
instructions in Figure 5.
A Bibliography
For those readers who wish to delve
further into machine code, the following
books are available (at least from U.K.
suppliers).
Understanding Your ZX81 ROM by
im ^c i he offset. Ian Logan. £8.95. The Essential Software
? 4... Company (Visconti Ltd.), 47, Brunswick
Centre, London W1 CN 1AF, and other
LD (HL),+00 2. out this Melbourne House outlets. Need I say
RET Enid anything more than that this book deals
. t 9 1 = .
16437 LD — HL(D-File) Pick-Up D-File. in the ZXB0/B1 systems. ааа.
iom n : he offset. Mastering Machine Code on Your ZX81
i Pe SUM or ZX60 by Tony Baker. £5.95. Interface,
LD (HL).+09 Puta brick in — 24 Earls Court Road, London W8 6EJ.
(HL), ut a "brick іп "Speak kindly of one's rivals and they will
this location. be kind to you."
RET Finished. Machine Language Programming for
Figure 4. Your ZX80 & ZX81 £8.95. Melbourne
The instruction ‘LD DE,+dddd’ loads a
2-byte constant into the DE register pair.
In the routine the first byte is altered as
required whereas the second byte always
stays as zero. The instruction ‘LD
(HL), +аа” is used to load a constant into
the location whose address is the current
value of the HL register pair.
In the 8K program one proceeds in a
similar manner.
1) Replace lines 10,180,190 and 220 by:
10 КЕМ 12345678901234567890
180 POKE 16518,L(R)
190 LET A=USR 16514 or
190 RAND USR 16514 (which looks nice)
220 POKE 16528,L(P)
225 LET A=USR 16524 or
225 RAND USR 16524
2) Load line 10 by using:
500 FOR А-16514 ТО 16533
House Publishers, 131, Trafalgar Rd.,
London SE 10.
The currently available books about
the 7Х81 are:
The ZX81 Campanion by Bob Maunder.
£7.95 Linsac, 68, Barker Road, Linthorpe,
Middlesborough Co. Cleveland TS5 5ES.
A very good book. Deals more with
‘computing theory’ and less with the
monitor than its predecessor.
Тһе ZX61 Pocket Book by Trevor
Toms. £4.95. Phipps Associates, 2, Downs
Avenue, Epsom, Surrey KT 18 5HQ.
From /nterface:
Getting Acquainted with your ZX81
by Tim Hartnell. £4.95.
30 Amazing Games for the ZX81 by
Alistair Gourlay. £3.95.
50 Rip-Roaring Games for the ZX80
and 2Х81. £4.95.
Hints & Tips for the ZX81. £4.25. Hew-
510 INPUT B son Consultants, 7, Grahame Close, Blew-
520 POKE A,B bury, Oxon. OX 11 9QE.
530 NEXT A Not Only 30 Programs for the Sinclair
RUN 500 Z X61. £6.95. Essential Software Company
and enter: (Visconti Ltd.), 47, Brunswick Centre,
42,12,64,17,0,0,25,54,0,201,42,12,64,17,0,0,
25,54,8,201.
which is the same routine as given for the
4K version but with ‘graphic 8’ instead of
‘graphic 9.’
London W1 CN 1AF, and other Melbourne
House outlets.
Again I would welcome seeing any
programs written as a consequence of
this article.
dec. hex.
LL A, dd 62 3E = LET A- ....
LD A,(addr.) 58 JA = LET А-РЕЕҚ.....
LD (addr.),A 50 32 = POKE...,A
INC A 60 3C = LET A=A+1
Figure 5.
19
4K ROM
ІК RAM
Introduction
I was pleasantly surprised to find that
the Sinclair ZX80 has both the software
and hardware facilities to expand memory
and I/O with relative ease. This conclusion
came after I had performed a few experi-
ments on the Z X80.
I would like to share with you these
experiments, their results, and my con-
clusions.
How the ZX80 Works
Before I could expand the memory or
add I/O to a ZX80, I had to know how it
worked.
The manual that comes with the ZX80
is of some help. There is also a hint into
the dynamic nature of the operating system
by virtue of the fact that system variables
are in RAM. This allows them to be altered
as needed by the operating system.
Though some may argue that the ZX80
is too simple to have an operating system,
it does have a central program that allocates
resources and passes control to the various
subprograms resident in the machine.
The important resource we are con-
cerned with here is memory, in particular
the user memory.
The book The ZX60 Companion, pub-
lished by Linsac, was most helpful in
supplying other good information, albeit
without an explanation of how RAMTOP
knows how to get to the top of RAM.
RAMTOP is the physical top, or highest
address of installed RAM. This top is
marked by the top-of-stack (TOS) marker
pair and 1095 (447h), the return address
for all Basic line executions. See Figure 1.
ЕАМТОР Ee. есес
TOS marker < _63 (ЗЕН) |
i м
әс fenes |3
pointer to < _ 4 (04H) | F
1095 (447H) 71 (47H)
Figure 1.
The Z X80 has a very пісе way of placing
RAMTOP and these four special bytes at
the top-of-stack.
David G. Sommers, 5155 Yarmouth Avenue, A part-
ment Z9, Encino, СА 91316.
20
Experiments in Memory
and І/О Expansion
David G. Sommers
ADR DT New
о 21 LD HL, 7FFFh ;
1 FF
2 7F
3 3E LD А, 3Fh Н
4 SF
9 C3 JF O261h Н
& 61
7 о2
261 56 LD(HL) , ОЛА Н
262 O1
263 2B DEC HL :
264 BC СР H ;
265 20 JR М2, %-4 Н
266 FA
267 25 INC HL Н
268 Ker DEC (HL) -
269 28 ӘК Z, %-? -
2600 ЕС
2ӨБВ F9 LD БР, HL Н
26C FS FUSH АҒ з
Figure 2.
As part of the NEW command, which
is executed on power-up or from the
keyboard, the total amount of installed
RAM is size checked by the subprogram
I shall call NEW. See Figure 2. I dis-
assembled NEW by hand using the
PEEK(n) command to read the ROM.
This routine starts by filling all possible
16K of RAM with Oth. Then, starting at
location 16384 (4000h) (see Figure 3), each
location will be decremented in value.
Next, the Z flag in the CPU status register
is checked to see if that location has
become OOh in value. If it has, this is
assumed a good memory location and the
next location is tried. This continues until
this test for zero fails. In the standard
ZXS$0, this occurs at location 17408 (4400h).
Here the actual location being addressed
Comments
ТОР RAM ADDRESS
TERMINAL COUNT
JUMP TO SEARCH FOR RAMTOP
STORE O1 IN ALL RAM
NEXT ADDRESSS DOWN
HAS 4000h BEEN FILLED?
LOOF CONTROL
INC FROM 3FFFh
DEC VALUE IN RAM LOCATION HL
LOOF CONTROL, IF ©,
CONTINUE LOOFING
LOAD SF WITH RAMTOF
START BUILDING TOP-OF-STACK
MAKER
is 16384 (4000h). This is due to the simple
linear-select for RAMCS (RAM chip select)
explained in more detail later. What hap-
pens now is that this location, having been
made 00h previously, now becomes ЕЕ.
This condition will cause the routine to
exit its loop and load the stack pointer
(SP) of the CPU with RAMTOP.
The search for RAMTOP has another
interesting feature. During one experiment,
that of adding 3K to the on-board 1K, I
discovered I had only a total of 3K, and
not the expected 4K. After many minutes
of sweating and cursing the ZX80, I found
that the very smart ZX80 had noticed
that one of my added 2114 RAM chips
was plugged in backwards, thus preventing
the top ІК from reading back 00h during
the search for RAMTOP. It is possible
SYNC Magazine
for a ZX80 to operate with bad memory
chips as long as at least the first ІК or so
still functions.
The last operational feature we need
to know is how the chip selects are derived
for RAM and ROM and how this know-
ledge might be applied to expansion.
Consulting the 7Х80 circuit diagram
(SYNC 1:1, pp. 24-25) I noted that the
ZX80 uses linear-selection for RAM and
ROM. A14 (address bit 14) is used to
divide the total address space in half. See
Figure 3. When AA14 is true (high), RAM
is selected; when false (low), ROM is
selected. This works fine if there is only
one ROM and one RAM (the pair of 2114
chips act as one IK X 8 RAM).
The weakness of this linear-selection is
that A10 through A13 are don't-care bits
as far as RAM chip select is concerned.
The ROM ignores A13 only. Figure 4 will
help illustrate the problem.
BASE
SHE ADDRESS
e -, 32768 (8000)
К 31744 (7C00H)
T ! ! 30720 (78008)
1K | | 29696 (7400H)
Ux | ! 286/2 (70008)
ик! | 2748 (82008)
10K | | 26624 (68008)
R ж. USER | 25600 (6400H)
A вк ! MEMORY | 24576 (60008)
м 7K | AREA : 23552 (528)
x ! | 22528 (59008)
ҚҰ! | 21504 (5400H)
aK | | 20480 (50008)
Ji | 19456 (ACOH)
xi | 18432 (4900)
IK | ; 17408 (4400H)
ж | ———— | 16394 (40008)
| REDUNDANT |
: (UNUSEABLE) |
R ! !
: o | 8192 (2000H)
M | EXPANSION AREA !
І FOR SK RON |
| ——— РНИ = 4076 (10008)
: 4K OPERATING
І SYSTEM AND |
! INTERPRETER |
be
Figure 3.
Novernber/December 1981
Address bits
15 14 13 12 11 10 9 S
p———————— spree «мен әсе омы» оғын кое seess lied
eme өзен еее оза» P soose оі qom Steed өмме «еее boose еее” TENE «өн осын cosse өцеее Shem: fonts Sone scosse
“ГЕРІ x к X мі----.-ЖКАМоыайагезкевк.......-------------“- i
KIES SEE So m me ee cae caen mem m ma ma m tained ROM addresses. i
16384 0) 1 Q о о © Q о о о о о Q о о о 4000H
17402 Q 1 о о о 1 о о ооо oO O O о о 4400H
17000 6 1 о 0 © © i1 в 6 i i 9 1 еө © 90 42463H
17048 Q 1 Q C 1 Q 1 Q Q 1 1 Q i 0 Q Q 4843H
! !
--- sence mase — cosse m— e— meee —— —— È
RAM don^t-care
x-dan^"t-care bit
Figure 4.
If the ZX80 reads memory address 16384
(4000h), the address bus will have the bit
pattern in Figure 4. The four don't-care
bits (A10-A13) are zeroes, so there is no
problem yet. Now the ZX80 tries to read
17408 (4400h). With A10 a don't-care bit,
the RAM thinks I want 16384 again. The
same thing happens if non-boundary
addresses are tried. Figure 4 shows what
occurs with 17000 (4268h) and 19048
(4A68h). Note address bit 11.
The ROM address space below 16284
(4000h) has a similar condition. If you are
a sceptic, try this program:
10 FOR I=0 TO 4096
20 IF NOT PEEK(I)=PEEK(I+8192)
THEN PRINT I;“AND”;I +8192;
“NOT EQUAL
30 NEXT I
This program will print any inequality
between ROM addresses 0 through 4096
and the redundant ROM space from 8192
through 12284.
I will be using A10 through A13 to
decode which 1K section of RAM I want.
Expansion into the ROM area will not
be attempted here. It would require AND-
ing A14 with A13 into IC13 pin 13 to
open up the address space from 8192 to
16383. I have considered doing this, along
with adding an EPROM containing
machine code peripheral drivers. The
USR(n) command could then be used to
access these routines.
Experiment in Hardware
I now know enough to design some
expansion hardware. The first thing I need
is a chip select decoder. I will use a 74LS138
1-of-8 decoder. See Figure 5-І. Then two
2114AL-4 RAM chips are added. This I
quickly lash together on a small general
purpose plug board.
The connector into the ZX80 was a
little harder. It is necessary to make the
connector by cutting down a standard
.100" center P.C. card edge connector. A
key for the slot at location 3 will also
have to be fabricated.
I started with a 50 contact dual-readout
connector for 1/16" board. The size of
the connector I started with was immaterial.
The larger versions of these connectors
are not usually marked with the same
alphanumeric numbering scheme as the
ZX80 circuit diagram, making hookup а
little harder.
I cut the connector with a hacksaw at
the points illustrated in Figure 6. It is
easier to cut the connector with the con-
tacts at location 24 removed. After cleaning
the cut areas with a file, I removed the
two contacts at location 3 to make room
for the key. On most connectors these
contacts can be removed by pushing on
them from the back until they start to
move, then pull from the front. A pair of
small needle-nose pliers will do the job. It
is a good idea to save these removed
contacts as spares. I managed to damage
a needed contact and was thankful for
my foresight. I made the key from a piece
of 1/16" expoxy-glass unclad circuit board.
I just snipped at it until it would force-fit
in place. My ZX80 connector was now
ready.
I was now able to complete the wiring
of my first expansion board. I chose to
ignore the fact that Sinclair connected
data and address lines somewhat capri-
ciously. You will notice that the ZX80
circuit diagram shows D7’, D1’, DO’, and
D2’ going to IC3, and D4’, D3’, D5’, and
DE’, going to IC4 in that order. I think
pins 5 and 7 on IC3 and IC4 being crossed
is a drafting error. Where is that famous
British precision and desire for order?
The reality is, of course, that it does not
matter; it is only a convention anyway.
After a few visual checks....... the juice
to it! I think so anyway. I quickly loaded
a program from tape that was pushing the
1K RAM to the point of shrinking the
display. I ran it....... no shrinking!
21
А1
HM6116P-4
|
|
П
[—
о кӛк іне на Әже ме Gres сей
І
1А-2
Figure 5.
BEN In Basic
23
CUT HERE
Figure 6.
I now need a little more definite check
for the size of RAM. The program SIZER
in Figure 7 will read the stack pointer,
SP, in the CPU and print the number of
bytes of RAM below it. When SIZER is
run, the value returned to the screen is 14
bytes short of the total installed RAM.
This is due to the ZX80 using the stack
during execution of the program, thus the
stack pointer is not pointing to the very
top RAM.
My first experiment was a success. I
now have the confidence to explore
further.
22
CD4050B
| А(0-10) 11 е. бе
100 LET F-17000
110 РОКЕ P,237
120 POKE P+1,115
130 РОКЕ P+2,112
140 POKE P+3, 66
150 POKE P+4,42
160 FOKE Р+5,112 LD HL,
170 POKE P+6, 66 RET
180 POKE P+7,201
190 LET SP=USR(P)
200 PRINT ,SP-16384; "#BYTES"
LD (17008), SP
(17008)
HDSP0772
In assembly language:
;LOAD SF INTO 17008
;LOAD 17008 INTO HL
;RETURN ТО BASIC
Figure 7. Sizer
I/O Expansion
By now I/O expansion seems trivial;
however, it is not totally trivial. I decided
that using I/O mapped I/O would be too
tricky due to the way the I/O address
space is consumed with the keyboard.
Besides, the PEEK (n) and POKE n,n
commands operate in memory address
space. So memory mapped I/O will be
the way.
I/O mapped I/O refers to an I/O archi-
tecture where the I/O device select lines
are decoded from IORQ (I/O request)
and the address bus. Thus, only instructions
from the CPU's I/O group would be used
to service these devices.
Memory mapped I/O refers to an I/O
architecture where MREQ (memory
request) and the address bus are used to
decode the device selects. Here, the device
SYNC Magazine
ж-, о
MEE аы
appears as one or more memory locations
to the CPU, and is treated such. The full
array of memory instructions can be used
on these I/O devices. In the ZX80, PEEK
(n) and POKE n,n are available.
One disadvantage with memory mapped
I/O in general is that it consumes part of
the memory address space. This is 1K in
my design for the Z X80.
My first I/O device will be simple
enough. I have some Hewlett Packard
displays; HDSP0772 to be exact. These
hexadecimal LED displays have a built-in
latch memory, decoder driver, and run
from +5 VDC. They also сап be spoken
to as if they were a memory chip with one
address. The only trick I need to play is
to buffer the data bus of the ZX80. The
group of resistors, R4 through R11, in the
Z X80, that presumably are in series with
the outgoing data lines to prevent a bus
crash, render the data bus rather puny. I
will use a CD4050B CMOS hex buffer.
See Figure 5-III.
NMOS and CMOS RAM chips require
no buffer because of their extremely low
input current requirement on the order
of 10 microamperes. The HP display
requires 1.6 milliamperes of sink current
on its data lines—a veritable short circuit
to а ZX80.
Figure 5-III shows a buffered display
configured at a memory address of 31744
(7С00Һ). The simple command POKE
31744,n will cause n to be displayed on
the LED readout. This Basic statement
can be imbedded in long running programs
as an activity monitor or possibly for games
as feedback.
The addresses of the I/O selects are:
Chip Select Address
CS16 31744 (7СООН)
CS17 31745 (7CO1H)
CS18& 31746 (7COZH)
CS19 31747 (7CO3H)
CS20 31748 (7COAH)
CS21 31749 (7COSH)
CS22 31750 (7COGH)
CS23 31751 (7CO7H)
These chip-selects will be active for
both PEEK (n) and POKE n,n commands.
With the simple I/O device in my experi-
ment, only POKE 31744,n will do anything
noticeable.
November/December 1981
I have not yet tried configuring an input
device to the ZX80. I anticipate no serious
problems in using a tri-state bus driver,
such as a 74LS244, connected to CS17
and the unbuffered data bus. This is to be
used to talk to the ZX80 from switches or
other devices. I simply ran out of board
space on my little plug board.
Further Memory Expansion
I have come into possession of a pair of
Hitachi HM6116P-4 CMOS RAM chips.
These 2K X 8 monsters are ideal for further
expansion of the ZX80 memory. They
are full static; no clocks or strobes. Even
the slowest family member, the -4, is more
than fast enough at 200 nanoseconds max-
imum access time. What is most desirable
is their low power consumption: 100 micro-
watts deselected and 180 milliwatts oper-
ating. By contrast, the ubiquitous 2114AL-
4 consumes 125 milliwatts, selected or
not, and has 1/4 the bit capacity. The
beauty of the Hitachi CMOS grows pale
when the price and availablity of these
exotic parts are considered. I was lucky
to get two of them cheaply.
The chip-select scheme in Figure 5-I
and 5-II allows for a mix of 1K X 4 and
2K X 8 parts. By using as many chip-
select lines as I have chips for, I can
configure any size memory I want. Please
note in Figure 5-II that two chip-select
lines are required for each 2K X 8 RAM
and that R19 in the ZX80 allows CSO to
override the chip select from IC12 pin 8.
At present I have 6K of memory operating;
the ІК inside, two HM6116P-4, and two
2114AL-4.
Consideration of Power and Loading
Power consumption and circuit loading
are very important in general, and crucial
in a ZX80.
I have estimated that the reserve current
in the ZX80 power system is about 100
milliamperes. At this level the wall unit
and the 7Х80 itself gets toasty warm.
Even this moderate heating will cause
some strange actions to occur. I notice
the LOAD function failed to operate after
the ZX80 had cooked with a 100 milli-
ampere load.
So far I have been unsuccessful in inte-
grating an auxiliary power supply into my
expansion system. My problem seems to
be 60 Hertz line noise getting into the
video. Most annoying. I believe my problem
stems from the fact that I am using a TV
set with a hot chassis and a slightly leaky
power transformer in the auxiliary power
supply I was attempting to use. I will fight
this problem some other time.
Though auxiliary power would solve
the power problem, so would the careful
selection of parts. The 74LS138 1-of-8
decoder is fairly stingy at 6.3 milliamperes.
The Intel equivalent 8205 is an outrageous
hog at 70 milliamperes worst case, possibly
35 milliamperes typical. One must be
cautious of functionally equivalent parts.
Look hard at the specifications.
CMOS will solve the power and loading
problems. The only problem with CMOS,
especially RAMS, is cost and availability.
Time will cure this, but I want it now.
That beautiful HP LED display I used
is a terrible glutton for power. That par-
ticular display is only good for demon-
stration of the ZX80 output capability.
There is a low-power version of this display
available.
Circuit loading is most crucial with I/O
expansion. As explained earlier, the ZX80
expansion data bus is quite puny. This
requires careful reading of chip specifica-
tions for input loading. A 74LS244 part
has a special PNP input circuit that loads
its source much less than standard low-
power Schottky. This allows direct con-
nection to the ZX80 data bus without a
CMOS buffer. Though workable, this is
still marginal at best. More exotic parts,
such as the 8212 I/O port, have even less
loading on their inputs. Again, the 8212,
though versatile, consumes 90 milliamperes
typically.
Conclusions
The ZX80 is definitely expandable with
ease. The operating system has been
designed with memory expansion in mind.
With the compromises that life presents
us daily, a very powerful version of the
ZX80 can be configured at moderate
cost. Fa
23
Қа ысын армен
^
8K ROM
16K RAM
An Inventory System
Dr. Stephen A. Justham
Mass data storage is accomplished more
efficiently by a disc system than by a
cassette recorder. However, until such a
system is available for the ZX80/1 com-
puters, Sinclair owners will have to rely
on the cassette system. This article offers
a program for a modest inventory system
based on the 8K ROM and 16K RAM.
For the sake of illustration, a “pantry”
inventory is used, but the program can be
adapted to any inventory you might want
to use it for. The program will handle up
to 150 separate items (Figure 1), but it
can be easily modified for the individual
user (lines 305, 307, 3044, and all the “B=1
TO 150" statements).
One begins by selecting choice 1, indicat-
ing the total number of items to be entered
(Figure 2), and INPUTing the item name
and quantity in response to prompts
(Figures 3 and 4). Once an inventory list
15 entered, the user has several options.
The search routine accepts a string input
(Figure 5) and searches the inventory to
ascertain if the item is in the listing. After
searching, the computer replies with either
a report on the item it has located (Figure
6) or a statement indicating that the item
is not in the inventory (Figure 7). A
complete inventory listing is available with
the third option. The program lists each
entry by item number, name, and quantity
(Figure 8). If the list is long, there is an
option at the end of the program to re-
check the listing.
New items are added to the inventory
by the fourth option. The current inventory
is listed and a prompt requests the new
item name and quantity (Figure 9). When
Dr. Stephen A. Justham, 8300 N. Costa Mesa Dr.,
Muncie, IN 47302.
26
X X X OXXOXOXCCCOGOXOXG GC
FAANTRY INVENTORY-10
XCKOCE X ECKE X XXX
THIS PROGRAM HANDLES 150 ITEMS
9292900290000:
DO YOU WANT TO:
і) ТАКТ A NEW INVENTORY LIST?
2) SEARCH FOR AN ITEM?
4) СНЕСЕ INVENTORY?
4) ADD NEW ITEM TO LIST?
5) CHANGE GUANTITY ОҒ AN ITEM?
6) DELETE AN ITEM?
7)EXIT PFROÜGRAM?
ENTER YOUR CHOICE,.1-7.
1
Figure 1.
START A NEW INVENTORY List
KKK KR KK KKK KEK ERK KKK RRR EMR KKK KER KE
HOW MANY ITEM ARE ТО BE LISTED’
РА!
Figure 2.
ITEM
NC.
1 ITEM МАМЕ? FEAS
HOW MANY? 9
z ITEM NOME? SUGAR
HOW MANY? 2
5 ITEM МАМЕ? BEANS
HOW маму? 19
4 ITEM NAME? CREAMED CORN
HOW маму?
не
Еісиге 3.
IF 99/7077" APPEARS IN THE LOWER
LEFT CORNER, TYPE"C"TO CONTINUE
LISTING
GUANT.
ITEM NO. ITEM NAME
i PEAS 9
2 SUGAR 2
5 BEANS 19
4 CREAMED CORN 5
END Or FILE.
ТҮРЕ "i1" TO RE-DU THE INVENTORY
LIST, "2" TO RETURN TO START GF
FROGRAH.
Figure 4.
SEARCH FOR AN ITEM
TYPE. THE NAME OF THE ITEM YOU
ARE SEARCHING FOR IN THE FANTRY.
"SALT "
Figure 5.
SEARCH FOR AN ITEM
KKKKKKKKKK MRE MR KKK KEK KER KKK KKK
ТҮРЕ THE NAME OF THE ITEM YOU
ARE SEARCHING FOR ІМ THE FANTRY.
THERE ARE 19 UNITS OF
BEANS
LOCATED IN THE FANTRY.
TYPE "i" TO SEARCH FOR ANOTHER
ІТЕМ, "2" TO RETURN TO START ОҒ
PROGRAM.
Figure 6.
SYNC Magazine
SEARCH FOR AN ITEM
22299999999229999990999090229:
ТҮРЕ THE МАМЕ OF THE ITEM YOU
ARE SEARCHING FOR IN THE FaGNTRY.
МО SUCH ITEM HAS BEEN FOUND IN
THE INVENTORY.
ТҮРЕ "i1" TO SEARCH FOR ANOTHER
ITEM, "2" TO RETURN TO START OF
PROGRAM.
1
Figure 7.
INVENTORY LISTING
HORROR KK KOK ROK KK KKK KKK KKK KKK KK
IF "5/777?" APPEARS IN THE LOWER
LEFT CORNER, TYPFE"C"TO CONTINUE
LISTING.
ITEM NO.
ITEM NAME GUANT .
і PEAS 3
> SUGAR 2
3 BEANS 19
4 CREAMED CORN че
END OF FILE.
TYPE" LT" TO EXAMINE INVENTORY, "2"
TO RETURN TO START OF FROGRAM.
Figure 8.
ADD ITEM TO INVENTORY
ЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖ Я
WHEN YOU WISH TO END NEW ENTRIES
ТҮРЕ "RETURBHN,"
IF "5/7777" AFFEARS IN THE LOWER
LEFT CORNER, TYPE"C"TO CONTINUE
LISTING.
ITEM NO. ITEM NAME QUANT.
i PEAS 3
2 SUGAR 2
3 BEANS i9
4 CREAMED CORN 5
ITEM MO. 3
ITEM NAMET SALT
HOW MANY
Figure 9.
November/December 1981
CHANGE QUANTITY GF AN ITEM
SESS SS SCCCCSCSSCCCCCCCCC CCC C SSS Е
IF "5/777" APPEARS IN THE LOWER
LEFT CORNER, TYPE"C"TO CONTINUE
LISTING.
aELECT ITEM TO BE CHANGED EY
"ITEM NO."
ІТЕМ NU. ITEM NAME GUNT.
1 FERES 8
i SUGAR e
k BEANS 1
4 CRERARNED:. CORN
a SAL. I
END Dr Fic.
SELECT ITEM TO BE CHANGED БҮ
МАТЕМ. MD,"
Figure 10.
(TEM NO. 4 IS CREAMED CORN
WHICH CURRENTLY CONTAINS 8
UNITS.
INFUT QUANTITY CHANGE.
Wok А "MINUS"SIGN TO REDUCE THE
QUANTITY.
Figure 11.
ITEM NO. 4, CREAMED CORN
HAS 35 UNITS.
„МОМ
TYPE"i"Tü CHANGE ANOTHER ITEM OR
"2" TO RETURN TO START OF PROGRAM
OR "Z"TÜ REVIEW THIS LISTING?
Figure 12.
DELETE AN ITEM FROM INVENTORY
KOKAK KK AOK KAAK KAAK ЖЕККЕН КЖ
EACH ITEM WILL AFFEAR ONE AT А
TIME.
1) IF YOU DO NOT WANT TO DELETE
THE ITEM TYPE "S."
2)1IF YOU WANT TO DELETE THE
ITEM TYPE "D."
3)IF YOU WISH TO TERMINATE
"DELETE" TYPE "T."
22999922929:
ITEM NAME
PEAS S
SUGAR D
BEANS
np H
Figure 13.
YOU HAVE INDICATED YOU WISH TO
EXIT THIS FROGRAM.
IF YOU HAVE MADE ANY CHANGES
2992999999999 9999990900 KKK KK KKK
ЖОО NOT FORGET TO RE-LOAD TAFEX
KKK KKK KKK KKK KKK KKK KK KKK KKK KK KKK
TO SAVE THIS FROGRAM AS CHANGED
FREFARE THE TAFE RECORDER, BEGIN
RECORDING, AND ТҮРЕ "C."2
9/2020
Figure 14.
the addition of items is completed
"RETURN" is typed to send the program
back to the menu at the beginning of the
program.
Since an inventory must always accom-
modate changes in the quantity of the
items, the quantity change routine is very
important. Option five, which first prints
the complete inventory, asks for the item
number of the item to be changed (Figure
10). After the item is selected, it is detailed
and the change is requested (Figure 11).
Finally, the item number, name, and
quantity change are printed out. The user
can then return to the start of the routine
to change another item (Figure 12).
The last option, aside from exiting the
program, permits the deletion of an item
from the inventory list. An item is printed
and the user inputs one of three choices:
save, delete, or terminate the routine
(Figure 13).
Exiting from the program and SAVEing
the program are combined in the last
option. The prompts remind the user to
re-load the tape with the up-dated inventory
list (Figure 14).
Several minor problems were encoun-
tered in attempting to develop a workable
inventory-type program for the ZX80/1.
Most notable of the “minor” problems
involved the way the 8K ROM handles
string arrays. This problem can to light
when the “SEARCH” routine was first (and
second, and third, and ...) attempted.
Finally, the attempt to use a "SEARCH"
routine was set aside. The solution to the
problem, which involved INPUTing an
"ITEM МАМЕ,” having the inventory
checked by the computer and then report-
ing whether or not the item appears in
the inventory came from a technique used
in another part of the program, lines 1080-
1084.
The difficulty involved in using the two-
dimension array is in the second dimension.
Once set (or simply using the 8K Basic
КОМ" own setting of 10 characters in
length) the ZX80 only recognizes an item
with the same number of second dimension
characters. For example, if an array state-
ment reads DIM (5,5), then five items,
five characters in length may be input. If
"PEAS" is typed in as an inventory item
the computer will store it as “PEAS blank
space.” In the search routine one must
27
try Ei
4K ROM users:
Enter the following program (this is
especially for ZX80 users in the US; other
national users are invited to contribute):
18 LET An&-" [ENTER
= SHIFT,H AND 15
SHIFT wl" |
20 LET B$=“ [ENTER
25 SHIFT Ы
зе FOR B-i TO 5
із PRINT AS
Se NEXT B 002
вә FOR Е-і TO =
7O PRINT БЕ
50 NEXT Б
Our thanks to:
Ted A. Pozyski
1215 Thompson St.
Houston, TX 77007
8K ROM users:
Enter the following program:
1@ LET L=USR 2193
20 FOR A=1 TO i88
30 NEXT A
да GOTO i8
RUN the program. When the cursor
reappears enter the program again and
RUN. (ZX81: be sure to use fast mode.)
Now turn up the volume on your TV set
to give the best output. You can use the
BREAK key to escape from the loop.
This one might even have a practical appli-
cation.
Our thanks to:
L. Richardson
82 Elgar Cres.
Cardiff, СЕЗ 9RW
United Kingdom қ,
ZX81 MINI
INVADERS
ALL THE THRILLS OF ITS BIG
BROTHER ON A 24x16 DISPLAY ALL
IN 1K RAM. £4 for M/C CODE CASSETTE
ALSO TV GAMES (16K RAM)
ZX 81 INVADERS
ZX 81 GALAXY WARS
m/c code routines with continuous non-
flicker display & fast moving graphics £4
each cassette.
J EDMONDS, 29 Chestnut Ave. Grays, Essex
28
type “PEAS blank space” in order to find
the item in the inventory. Typing “PEAS”
will not be accepted as “PEAS blank space.”
Lines 3040-3068 overcome this problem,
mainly through the LEN function used in
conjunction with a string and the one-
time use of a string array.
The “DELETE” routine also proved to
be something of a programming challenge.
Originally an item could be deleted, but
the item number remained with a blank
for the item name and an “O” for the
quantity. An associated problem involved
the fact that the items were not moved 1,
2,..., or n places (depending upon the
number of items deleted), but were clipped
from the end of the list. These cumulative
difficulties were overcome by introducing
several variables, lines 1610-1618, and then
using them at appropriate places through-
out the routine; notably lines 1820, 1840,
and 1908. Other manipulations such as
found in lines 1830, 1835, 1900, 1909, and
1920 were employed to achieve the desired
deletion and renumbering results.
Program Notes:
“PANTRY” may be changed to
whatever inventory you want.
If a number other than 1-7 is typed,
this sends the computer back to
90 to start over again.
Sets the first dimension of the two
dimension array equal to one more
than necessary for the "DELETE"
routine to function properly. The
second dimension may be changed
to meet individual needs.
Starts a loop that continues until
told to leave—line 390—or the
maximum “В” — 150— 15 reached.
“X” equated to “В” in order to
evaluate *N" without involving "B"
directly.
This and similar lines may be
removed if the prompt is not
needed.
Any INPUT other than "P" starts
the program over.
These are necessary in order to
increase the number of items
INPUT at the start of the program
in line 310.
Increases “В” by one each time a
new item is INPUT. |
C$ is used and handled in this
manner; otherwise the ZX80/1 will
not read the “RETURN” order in
line 1084. This involves the way in
which two dimension string arrays
are handled.
This line removes the "ITEM NO.,"
“ITEM NAME,” and “QUANT.”
line on which “RETURN” is typed,
5,7
160
305
332
370
ЭТӘ
400
490
960
965
1040
1080
1081
1082
1125
Many “frills” have been used in the
program and may be easily eliminated if
so desired. For instance, the asterisks and
many PRINT statements may be removed
without affecting the program. These frill
lines are marked by an * in the program.
The total number of items may also be
reduced. (NOTE: be sure to keep the first
dimension of the two-dimension arrays one
more than the total number desired, other-
wise problems may occur in the deletion
routine if the total number of items possible
is used.) In all cases, it has been assumed
that the user will know when to hit NEW-
LINE, therefore, this does not appear in
any PRINT statement.
Other routines or data variables may
also be added to the program. If location
is important this variable may easily be
included possibly as a string variable. More
generally, this program may be readily
adapted to any type of inventory situa-
tion.
otherwise “RETURN” shows up as
an item in the program.
Increases or decreases (if minus
sign is used) the quantity of the
item.
Used to accommodate the mani-
pulations employed later to handle
the “DELETE” aspects of this
routine.
Removes the deleted item from the
file then sets the quantity to 0.
Increments “B” by one to continue
printing of the file after an item
has been deleted.
Decrements “М” by one for each
item deleted.
Re-sets “В” equal to what it had
been originally, for renumbering
purposes following a deletion.
1370
1610
1615
1618
1800
1810
1830
1835
1900
1908
3040 Because of the manner in which
3042 the 7Х80 handles two dimension
3044 string arrays the only way (at least
3048 to the author's knowledge) to
3052 initiate a search is to INPUT a
simple string array —line 3040—
equate the array to its numerical
length — LEN in line 3042— set up
a new two dimension array with a
variable second dimension — “J” in
line 3044— start a loop— line 3048—
equate the new string to the item —
line 3052—and compare the
INPUT, C$, to M$(B) (which is the
same as 1$(В)). If C$ is the same as
MS(B), then the computer jumps
to line 3100 and reports that the
item is in the inventory and tells
how many units are present.
SYNC Magazine
Fred D'Ignazio and Stan Gilliam have
created a delightful picture book adven-
ture that explains how a computer works
to achild. Katie “falls” into the imaginary
land of Cybernia inside her Daddy's home
computer. Her journey parallels the path
of a simple command through the stages
of processing in a computer, thus
explaining the fundamentals of computer
operation to 4 to 10 year olds. Supple-
mental explanatory information on com-
puters, bytes, hardware and software is
contained in the front and back end
papers.
new friends?
“for your child...
.-—— Katie and the Computer
| educational."
Thrill with your chidren as they join the
Flower Bytes on a bobsled race to the
CPU. Share Katie's excitement as she
encounters the multi-legged and mean
Bug who lassoes her plane and spins her
into a terrifying loop. Laugh at the
madcap race she takes with the Flower
Painters by bus to the CRT.
"Towards a higher goal, the book
teaches the rewards of absorbing the
carefully-written word and anticipating
the next page with enthusiasm..."
The Leader
"Children might not suspect at first
there's a method to all this madness—a
lesson about how computers work. lt
does its job well."
The Charlotte Observer
“the book is both entertaining and
Infosystems
The Colossal Computer Cartoon Book
Do
The best collection of computer cartoons ever is now in
Order Today
Katie and the Computer is hardbound,
illustrated in full color throughout and costs
just $6.95. A T-Shirt picturing the program
bug in the story is also available (purple
bug on a beige shirt). Shirts are available
in adult S, M, L, XL, childrens S, M and L
and cost just $6.00.
To order send payment plus $2.00 postage
and handling per order to the address
below.
creative
competing
39 E. Hanover Avenue
Morris Plains, NJ 07950
Toll-free 800-631-8112
In NJ 201-540-0445
Computer
Enthusiasts
Have
More
Fun?
I Ж
/
iTS TIME FCR
YOUR FAVORITE SCIENCE
Fic TION PROGRAM
its second printing, and sports a bright new cover. The
fifteen chapters contain hundreds of cartoons about
robots, computer dating, computers in the office, home,
and lab, and much more. 36 cartoonists share their views of
man’s ultimate machine.
Keep this book with your reference works. When
needed, the right cartoon can say it all for you. When you
need a break from debugging a good laugh can give you a
welcome lift. Recommended for hours of fun and comic
insight.
Edited by David Ahl, mastermind behind the April Fool's
issue of Dr. Kilobyte's Creative Popular Personal Re-
creational Micro Computer Data Interface World Journal,
this cartoon book contains much of that same incurable
zaniness. [Want this issue? It's April 1980 and only $2.50
postpaid].
A large 87 x 11” softbound collection of 120 pages, it still sells for only $4.95. (6G).
To order, send $4.95 plus $2.00
shipping and handling to Crea-
tive Computing Press, P.O. Box
789-М, Morristown, N.J. Or
call in your MasterCard, Visa,
or American Express order toll
free: 800-631-8112 (N.J.(201)-
540-0445).
Listing:
2 REM STEPHEN à.» JUSTHAM,
5 REM "PANTRY INVENTORY-10"
PRINT TAB 73s "XXooooooooooock
PRINT
mY-io"
PRINT
tt
ТАН Sa "PANTRY INVENT
ТАН 7; UoxOk ROOK OK ORO E
LTEM TI ý
TAR Уз OEXXXEX XXXIX
i3o
K11 PRINT
PRINT
c0 PRINT
a PRINT
AQ PRINT ТАН
INVENTORY
40 PR TAR 2"
"DO YOU WANT TO:"
d A START A NEW
Liaise
NT 2 )5ERRUOH FOR A
N ITEM?"
PRINT ТАН
ÜRY?"
AQ PRINT
ТО LIS
75 PRINT ТАН
ІТУ ОҒ AN
FRIT TAB
EM?"
Goa PRINT
ған
ІМУЕМТ
e
Ж
м"
ri
n
pm
ғғ;
е
ын
p?"
"ауар NEW ITEM
ша
Z3 "5)CHANGE QUANT
ITEM?"
2:"6)DELETE
АМ IT
ТАН 2s"7O)EXIT PROGRAM
SINT
SENE
“ENTER YOUR CHOICE, 1-
THEN 6070
THEN GOTO
THEN GOTC 600
THEN GOTO 900
THEN GOTO 12
THEN GOTO 1500
THEN GOTO 2000
525,7
AOUQC
CC)
IF Аш?
GüTO 9o
PRINT TAR Ba" START А
VEMTORY LIST"
PRINT OOOO ЖЖЖ ҰЖЖХЖЖЖҠЖЖ
OOO OK"
SO2 PRINT gj
PRINT HOW MANY
0, BE“LASTED? "Ф
DIM 16151,15)
“DIM сову |
INFUT' N н
GELS
S22 PRINT
2 PRINT
A26 PRINT
X28 PRINT
S32 FOR Bei TO 150
PRINT TAR 2;B;"4"
PRINT "ITEM МАМЕ?"
INFUT 108)
PRINT TCE)
PRINT TAB 5; "HOW MANY?",
A695 INPUT, Б) А
ERINT-GOQPr а ау
370 LET ХаВ
375 IF ХаМ
ЗО NEXT В
CLS
PRINT
IN THE
2 m
Note:
қалы
FINT
EM МАМЕ
FUR Бі TU
PRINT TAB
: TAR 26:
ШЕТ ХеВ
IF Хс«М
NEXT E
MEW IN
ITEMS ARE T
“ҮТТЕ
TAB Fr "мо. "
THEN GOTO 390
"IF 88g 79990" APPEARS
LOWER LEFT CORNER Ty
TO CONTINUE L
ME jg shitt
п и
Ho
Ci]
"STAR 1O;"IT
"QUANT."
oen
"ITEM МО.
ТАН 245
jx
Т?
GO)
TAB ii: i$0D
THEN GOTO 470
io] LNG.
Hi
.EH-D-B1
470
X 501
602
eu.
340
go
9 60
365
cy 1 ur та
J 00
FO
i000
1010
1020
1030
1040
1045
1048
1050
1060
1570
1080
1081
1082
1084
PRINT
PRINT
PRINT
"END DP FILE,"
ТП BE-DL
e$ VI
-.
“ТҮРЕ чаз es
THE INVENTORY LIST,
RETURN TO START OF
INFUT P
CLS
IF F=1 THEN GOTO
IF Fe ti THEN GOTO &
PRINT TAR Za "INVENTORY
ING"
PRINT "RR RK RRR KOK KR RK RK EK KKK
XX Kk XX X X XXOERXXU
PRINT
PRINT "IP "Uümygv"'? o gQAEMEERESG
IN THE LOWER LEFT CORNERS
TYPE C PGE STE CONTINUE##
LISTIMG."
iia a
PROGRAM.
OD
Lio
TAE
"QUANT."
"ITEM NO. ":
TEM NAME"; тав 24;
FO Bei
LET X=E
PRINT TAB Sah; ТАБ iiil$iu
; TAR 26; CB)
IF XZ2N THEN
PRINT
PRINT
GOT
NEXT E
PRINT
RINT "TYPE""j
11. incu n
START OF PROGRAM."
iNPUT D
CLS
joi"
са
EGET Ci
"ERD UP FILE."
eut
no
APP LT AE
Та E
Tu
THEN GOTO éoo
THEN GOTO &
ADD ITEM
Deed
PRINT Тан óp"
VENTORY"
PRINT "ЖЖЖ ЖЕЖ ooo ЖАО
is DOOOOIOOIOOE KE"
SINT
TO i
TO END
TURIN,
Wiz
ы uu ae
Y OU
ТҮРЕ
“ИНЕМ
MEW ENTRIE
PRINT
PRINT "IF ""5/2??"" APPEARS
IN THE LOWER LEFT ER
""C"" TO CONTINUE SRL
RINT "ITEM NO."; Тай
TEM NAME" з |
PRINT
FOR El
PRINT TAR Шұ;
; TAR Z6sü
LET X«H
BN
luo
TO
Ган
82 Sab REAL
Lis ie ake)
Кеше
i040
THEN GOTO
iF GÖTÜ
NEXT 8
PRINT
PRINT
TO START
STOF
GOTO 6
LET B=B+1
LET МеВ
IF G-B
PRINT
PRINT "ITEM NO.";B
PRINT TAB 3;"ITEM NAME? ";
INFUT C$
PRINT C$
LET I$(B)=C$
IF C$=" RETURN"
2
"SORRY, FILE IS FULL
“ТҮРЕ "рен TO RETUR
OF PROGRAM. ”
THEN GOTO 1000
THEN GOTO 11
TO
RE TURE TO
1090
1100
1103
1100
1120
1125
1130
L200
kio
1210
1212
1214
1:220
Looe
1230
1235
1240
1260
1270
1280
12835
1290
Аба
500
іліп
1520
ANGED BY
1330
o3
*1:40
PRINT
INFUT
CLS
GOTO
CLS
LET NzB-1
GOTO ё
РКІМТ TAB 23; "CHANGE GUGNTIT
Y OF AN ITEM"
PRINT "XKKKKKKEKKKKKKKKKKKK
ЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖ"
FRINT
FRINT "IF AF FEARS
IN THE LOWER LEFT CORNER TYFE
""C"" TO CONTINUE LISTING."
ЕКІМТ
ЕКІМТ
ANGED BY
PRINT
PRINT "ITEM NO."; TAB 10;"I
TEM МАМЕ"; TAB 24% QUANT."
ЕКІМТ
FOR Есі TO 150
LET X=E
PRINT TAB
; TAR
IF X<>
PRINT
PRINT "END OF FILE."
GOTO 1210
NEXT E
FRINT
PRINT
TAB 2; "HOW MANY? "s;
(GB)
1040 |
ee тан
“SELECT ITEM TU BE CH
ын" І ТЕМ NO " Hon dH
5s Bs
263 0 CE)
N THEN GOTO 1
TAB i1:I$(E)
ROCO
“SELECT ITEM
“ITEM NU.
TO БЕ CH
INFUT Е
CLS
РКІМТ "ITEM NO.4":Es;"4ISH";
1Ф (Е): "#ЫНІСН CURRENTLY
CONTAINS #"30(B)s "###UNITS. "
42 PRINT
1560
Ізб62
1370
жізео
1400
1405
1410
1420
14295
1500
Ж1ЗО1
1510
1220
1530
1540
15
1550
tn en
: Ef
ER Б
f
tf ІҢ
“4.
2 PRINT
РКІМТ
E."
PRINT
"INFUT QUANTITY CHANG
"USE A ""MINUS""SIGN
TO REDUCE THE QUANTITY."
INPUT k
CLS
LET QD =0 (Б) +k
PRINT "ITEM NO.4";Bs",
(E) р", "р "NOW HASS"sQ(
NITS.
FRINT
FRINT "TYFE""1""T( CHANGE A
NOTHER ITEM OR""2""TO RETUR
М TO START OF PROGRAM OR
i"" TO REVIEW THIS LISTING."
INFUT R
CLS |
IF R=i THEN GOTO 1220
IF R=2 THEN GOTO 6 |
IF R=3 THEN GOTO 1200
PRINT TAB 2; "DELETE AN ITEM
FROM INVENTORY"
PRINT OOOO OO GK
ЖЖЖЖЖЖЖЖЖЖЖ
FRINT
FRINT "EACH ITEM WILL.
R ONE AT А TIME.
PRINT
PRINT ТАБ 2;"1) IF YOU DO NO
T WANT TO DELETE THE ITEM
ТҮРЕ" "5,
H", 1S
E) "sU
noi
АРРЕА
інін
5 РКІМТ
PRINT ТАЕ
ТО DELETE
D. Hb on gn
FRINT
FRINT TAE
YOU WANT
TYPE uu
2;"S)1F
THE ITEM
28$") IF YOU WISH
SYNC Magazine
Ет
K1iS65
ж1567
ж1570
KIS7S
1580
1371)
1400
1610
1615
1618
1620
16350
1629
1640
1650
1660
1665
1670
1622
1690
1710
17:20
Іле
1730
1735
1740
1750
TO
РЕ
PRINT
FRINT
PRINT
PRINT
PRINT
FOR
IF ІФ
LET YsB
Х= Е
L=N
LET
LET
PRINT
INPUT
PRINT
ij Е
IF
oe
GOTO
C.
X
E:
Z$="S"
2 $= if D it
IF Z$-"T"
TERMINATE
n wT a нын
""рЕ ЕТЕ" "
“KARR KKK KEK HK"
"ITEM МАМЕ"
TO
(E) =" "
TAR
2%
2%
1520
GOTO ё
LF
BM
NEXT В
PRINT
PRINT
PRINT
PRINT
PRINT
SH TO
РЕ нн
ғ",
p
"END ОҒ
"TYPE "
DELETE
ні
TEC
ФСБ) з
d
THEN GOTO 1
THEM BATO 1
TY
val)
if # н H
THEN GOTO
THEN GOTO
THEN GOTO
1710
1800
1679
FILE."
атлы.
OTHER
LF
TO RETURN
YOU WI
(TEMS, ТҰ
TU
1760
1769
1770
1780
1800
1810
18315
1829
1820
1835
1840
1850
1900
1908
1909
1910
190
1950
OUO
2020
OO
дері)
SOC)
5 PRINT
INFUT W
CLS
IF Wei THEN GOTO
ІБС>1 THEN GOTO 6
LET ІФ (В) =" "
LET ОВ) =0
IF МеВ THEN БОТО
FOR Bev TO 150
LET 1$(B)=1 (B41)
LET 08) =G(B+1)
IF ZzB THEN GOTO
NEXT В
LET МеМ-і
LET ВХ
IF NeE THEN GOTO 1730
GOTO 1590
LET NzN-i
GOTO 1730
PRINT "YOU HAVE
OU WISH TOSSEXIT
Ам."
1500
1"20
1900
INDICATED Y
THIS FROGR
5 PRINT
РКІМТ "IF YOU HAVE MADE ANY
CHANGES”
2 PRINT
© PRINT
NOOO OOOO KKK KK K X
ЖЖЖЖЖЖЖЖЖ"
"XDO NOT
-LOAD TAPEX"
PRINT OOO OG K KKK X
WOOO OOK"
PRINT
PRINT "TO SAVE THIS PROGRAM
AS CHANGED ЕКЕРАКЕ THE TAFE
RECORDER, BEGIN RECORDING,
AND TYPE "g, "nun
STOF
SAVE "FANTRY
GOTO 6
PRINT
FORGET TO КЕ
INVENTORY-10"
TAR
KOLO
TORO
ROO
REDEE)
Od
Og
AQ
SUD
2088
RO FC)
2075
AOBO
5090
5100
ЖӘТУ
5104
x3120
Xl
X124
3140
PRINT "ЖЖЖ ХХХ ЖҰЖ
OOOO KOK!
PRINT
PRINT THE МАМЕ OF
ITEM YOU##ARE SEARCHING
IN THE PANTRY."
ІМЕШТ C$
LET JeLEN C$
DIM М%(151,4)
FÜR Bei TO 150
LET МФВ) T$ (E)
СФеМ%(Б) THEN GOTO
NEXT B
PRINT
PRINT "NO SUCH
М FOUND INSHETHE
БОТО 5120
PRINT
PRINT
PRINT
PRINT "THERE ARE" sO) CEQ "4
UNITS GF"
PRINT
PRINT ТАБ
PRINT
Y"
FRINT
PRINT
PRINT
PRINT "TYPE
FOR ANOTHER
RETURN TO START
INFUT U
CLS
IF
"TYPE
THE
FOR
5100
ITEM HAS REE
INVENTORY. "
2:0%
"LOCATED IN T
TO SEARCH
it "ean " yg
PROGRAM. "
1+ тазы ib
ITEM,
OF
(еі THEN GOTO 3000
73 "SEARCH FOR AN
PROGRAM. " LTEM" IF Us el THEN GOTO 6
ciné! ZETATREK™
ADVENTURE SERIES (ZX80 8K/16K)
START OF
NOW AVAILABLE
keyboard.
CONVEFSIONS
е Standard Computer H
In ZETATREK #1, you pilot a scout/fighter craft out of Space Station
HEINLEIN patrolling the North Polar region of the Solar System
against the warrior Lizardmen...origin unknown.
#1 features launching, docking, and target practice, but when you
encounter enemy craft, there is only ONE level of difficulty: “kill or be
killed”!
Tape and listing: $19.95
Tape only: $14.95
(Add $2 shipping &
handling. User-entry
listing not available.
Orders paid by Money Order
sent soonest: Please allow
4 weeks delivery if by check.)
TO ORDER ZETATREK #1
Send payment to:
ZETA Software ZT-1
P.O. Box 3522
Greenville, SC 29608-3522
WRITE for free catalog describing
more than 45 1K-titles in 4K or
8K ROM and several 8K/16K
scientific programs from
DELTASOFT Germany.
Wired keyboard, complete with plans $65.00
In Europe, send $1 bill
or DM2 in stamps to:
DELTASOFT
Dr. Walter Diembeck
tOsterfeldstr. 79d
ж à D-2000 Hamburg 54
Germany
Mail for information:
L.J. H. Enterprises
P.O. Box 6273, Orange, CA 92667
For information or Visa or MasterCard orders call
(714) 772-1595. Shipping charge for U.S.— $5.00.
November/December 1981 31
4K ROM
ІК RAM
In Part 1 (SYNC 1:5) we saw what a
READ statement is, how it functions, how
to run a machine language subprogram
with the USR function, and how to get
your machine code into memory with Basic
loader program.
In this part I will give you the machine
language READ subroutine, present a few
tips on how to get it running, and describe
a couple of the features of the Sinclair
system that I made use of when I wrote it.
If you typed your loader program in last
time and SAVEd it, you should be ready
to go.
The READ Subroutine
Listing 1a and 1b show you what your
TV will look like when you type the
subroutine in. Listing 2 has the same
information in the column headed
"Machine Language" that listings 1a and
16 have, but Listing 2 has much, much
more information for those who want to
see how this thing works. It has extensive
comments on the overall design, more
comments on the individual instructions,
and the assembly language. When I pro-
gram, I figure out what I want to do (the
overall design) and how to do it. Then I
write that in assembly language, and only
as a last step do I convert the assembly
language to machine language. АП of that
is in Listing 2.
A READ Revisited
I started this whole discussion in Part 1
by talking about the need for a method to
READ numbers out of special program
lines into array elements. In the first Listing
I showed what a READ might look like if
we had one in this Basic. Now that we
have a subroutine that performs the same
function, I would like to come the full
circle and show how I would adapt that
hypothetical listing to function with this
subroutine. I think Listing 4 says it all.
Try adding these lines to your subroutine
and its supporting lines! Do not forget the
comma in line 70!
I like this set-up because it looks and
functions a lot like the ideal that I am
trying to emulate. It does have a few
differences, however.
Numbers and Non-Numbers |
I said before that the subroutine will
not function if the word "DATA" is
misspelled or if there are spaces between
the letters. READ statements in other
Basics are usually sensitive to spelling but
not to spacing.
Edward A. Kennedy, Jr., 16 701 Red Oak St.,
Bensenville, IL 60106.
32
Part 2
Machine Language Teaches
the 7Х80 to READ
Edward A. Kennedy, Jr.
Listing 1a. READ subroutine, machine language,
first par. When you press NEWLINE after typing
in the "25" in the bottom line, your screen will go
blank for a moment. Then you will see the first
three lines shown in Listing 1b, and the 25 will be
the first number in the fourth line.
11 08 ЗЕ 14 1A F5
F5 Dl 2F F5 ы Fl O6 08
OF CB 1B 10 ЕВ 2F 06 08
1Е CB 1D 10 ЕВ 25 13 12
D5 DS 1A F5 13 lA F5 Dl
Fl 06 08 iF CB 1B 10 FB
СІ 05 02 OA OF 28 29 13
E5 19 EL 20 09 Cl 01 OO
2Е Oh 3E 01 O2 CO 1A FE
29 20 EC 15 1A FE 26 20
E6 13 1A FE 39 20 EO 13
1A FE 26 20 DA ЗЕ 01 02
21 00 00 12 1A ЕЕ D 28
"aon"
Listing 1b. A continuation of Listing la. Note that
the first three lines across the page are the last
three lines from Listing 1a. Continue typing with
the second number in the fourth line of this list-
ing.
E6 13 1A FE 29 20 EO 13
lA FE 26 20 DA 3E 01 02
21 00 00 12 1A FE D8 28
25 06 3B СВ OO B8 28 18
D6 1С 38 EF FE OA 20 EB
29 E5 29 29 Cl 09 06 08
1F CB 19 10 ЕВ 09 18 DB
СІ cS 05 05 АЕ 02 E3 EB
E3 СІ C5 06 08 CB 19 IF
10 FB 12 Fl 15 12 C9
Listing 3. Seven lines that сап be added to the
loader program (Listing 4 in Part 1) to check out
the READ subroutine after it has been stored at
line 1.
10 REM DATA 1,2,3,4,5,6,7,8,9,
10,11,12
15 FOR J-1 TO 23
20 LET L-USR(16h27)
25 PRINT L,U(O),U(1)
30 NEXT J
25 STOP
1200 REM DATA 101,102,103,, `
Listing 4. Using a subroutine (located at 16,427 in
RAM) to simulate a READ on the Sinclair with a
4K Basic. Notice that line 50 is a REMark. Also,
line 30 does not "READ A(J)" but LETs A(J)
equal the value returned by the machine routine.
10 DIM A(50)
20 FOR J=0 TO 50
20 LET A(J)=USR(16427)
ho NEXT J
50 REM DATA 174,39,317,255,78,
121,286,228,225,152,158,186,257,
241,85,161,24,145,50,271,28,106,
165,95,213,206,95,261,80,58,259,
296,25,1,178,132,268,11,259,250,
279,291-,66,525,179,115,81,66,95,
200,281
60 FOR Z=0 ТО 50
70 PRINT А(2),
80 МЕХТ 2
SYNC Magazine
This one is like the others in that it
ignores spaces between numbers.
е: “КЕМФОПАТА»17е94ө6 3009 3917,
2,000005005 007008 е(е(с.)
This works fine. In fact, it does not even
care if the spaces are turned into letters.
Even this:
ee5)eREMeDATA9*17WHAAT 23A €9,
317,
2BUNCHS5OF5JU7NKS8,e(etc.)
does not bother it. You will not find another
READ statement anywhere that will READ
that line.
Negative Numbers
Just for a test, you might want to add a
few minus signs in front of your numbers.
50 REM DATA -174,-39,-317,255,
78, (etc.)
Shucks! When this is RUN, the subroutine
ignores the minus signs just like it ignores
the other junk we gave it, and we still get
positive numbers. But if we try subtracting
each of these numbers from 65,526:
65,536 - 174 — 65,362
65,556 - 39 - 65,497
65,536 - 317 - 65,219
65,536 - 255 - 65,281
and place the results in our line of DATA
where the negative numbers were:
50 REM DATA 65362,65497,65219,
65218,78, (etc.)
Eureka! It works! But why does it work?
The answer to that lies in the way a
computer handles positive and negative
numbers. It uses a system called “two’s
complement representation.” If you want
to know more, I suggest that you pick up
a good book on Z-80 microprocessor
programming and look up two's comple-
ment. The first of the two books by Nichols,
Nichols and Rony (see References in Part
1) has an excellent six-page discussion of
two's complement.
System Features That the READ Subrou-
tine Uses
In this project, I made use of two system
features, which I will describe.
Finding a Variable
You cannot use the READ subroutine
without including the following line in
your Basic program:
2 DIM U(1)
Getting It to Work
1. LOAD the loader program from Part 1.
a. The REMark line has been numbered line 1 to make
sure it stays in the same location in RAM.
b. There need to be as many minus signs in line 1 as
there are bytes in the program plus maybe one or two
extra for safety. This program is 159 bytes long.
c. SAVE the loader for your own experiments in pro-
gramming.
2. Now, RUN it. Your screen will go blank except for the
cursor in quotation marks in the upper left corner.
a. It is looking for a hexadecimal number (0 thru 9 or A
thru F) or for the command to stop which is an "S".
b. Always give it two numbers! If you want to enter "8"
type "08" and not "8"! Press NEWLINE when you are
satisfied with your entry.
c. After you enter the 105th byte, the program will take
a moment to erase the top ten lines, and will reprint bytes
numbered 81 thru 105. After the 159th byte, the program
will automatically stop.
d. To correct an error (ten bytes back for example):
1) Stop the program by typing “5” апа NEWLINE;
2) Change the address by typing LET I=I-10 and
NEWLINE;
3) Press CONTinue and NEWLINE;
4) When the error has been corrected, you can get
back to where you were by using a similar procedure to
add nine to I.
3. Now enter the subroutine shown in Listing 1a, and in the
bottom seven lines of Listing 1b. The top three lines shown in
Listing 1b repeat the bottom three in Listing 1а. This will be
helpful if you write your own machine programs.
a. Check your code carefully against the listings. The
Sinclair system will not check for errors in machine code
like it does in Basic. One error could cause you to bomb
and lose the whole program.
b. SAVE a copy right now. If it does bomb because of
an error that you misssed, you will not have to start all
Over.
November/December 1981
4. Now it is time to make sure it works.
a. The lines in Listing 3 can be added to test it.
1) The keyword REM in lines 10 and 1200 allows us
to type the word DATA, which the subroutine needs.
2) DATA lines have no comma at the end. I put two
at the end of line 1200 to show how that messes things
up.
b. When you RUN it, check the display as follows:
1) The numbers in the left column are the DATA
that was just READ out of lines 10 and 1200. Note the
extra zeros at the bottom. These are caused by the
commas at the end of line 1200.
2) Each number in the middle column is the address
of the comma or EOL (End-Of-Line) marker following
the piece of DATA to the left of it in the same row. If
your addresses are not the same as mine, do not worry
about it.
3) The numbers in the right column are the flags. A
one says it came back because it found a comma and
there are more numbers in the line. A zero says the
subroutine found an EOL and must look for another
line of DATA if it is called again.
4) The “2:20” in the lower corner of the screen says
that the subroutine ran out of DATA. We asked it to
do twenty-three READ operations, but only gave it
eighteen numbers to READ.
c. Did your display do all that? If it did not function
properly, the problem could be with the Basic or with the
machine code.
1) In the Basic the word “DATA” must be spelled
correctly with no spaces between the letters. Also,
commas between the numbers must be commas and
not periods.
2) If that is not the problem problem, check the
machine code again.
5. If it works right, you can take out all the lines numbered
ten and higher.
a. What you will be left with is the bar subroutine in line
1, the next two lines which it needs to function properly
(line 2 and line 3), and line 5, which is not essential but will
help to remind you where to find the start of subroutine.
b. If you SAVE a copy or two of this, you will have it
ready when you want to convert a program that needs a
READ.
33
Listing 2. The READ subroutine — assembly and machine languages with
addresses and comments. (Only relative jumps are used, so addresses are
re-locatable ).
Listing of a subroutine that simulates a READ statement with the Sinclair
4K Basic. Prepared June 7, 1981, from a hand-assembled source by Edward
A. Kennedy.
Machine Labels Comments
Language
Assembly
Language
Location
Decml / Hex
Point the DE register-pair to 4008 hex (16392 decimal). The 16-bit
number stored there at the next location is the vector pointing to the
beginning of the user's variable file. Copy it into the DE pair and put its
twos-complement into HL.
16427 / 402B 11 08 zF LD DE,3FOBH ;Put 4008H
16430 / 402E 14 INC D ; into DE.
16431 / +02Е 1A LD A, (DE) ;Get lo byte of vector
16432 / 4030 F5 PUSH AF ; and save it.
16433 / 4031 13 INC DE
16434 / 4032 1A LD A, (Dz) ;Get hi byte
16435 / 4033 F5 PUSH AF ; and transfer it
16436 / 4034 Di POP DE ; to D.
16437 / 4035 oF CPL ;And its ones complement
16438 / 4036 F5 PUSH AF 2 goes
16459 / 4037 El POP HL ; to H.
16440 / 4038 Fl POP AF ;Retrieve the lo byte
16441 / 4039 06 08 LD B,O8H ; rotate it circular
16443 / 4o3B OF LOOP RRCA ; back into itself
16444 / 403C CB 1B RR E ; and into E
16446 / 403E 10 FB DJNZ LOOP ;(FBH = -5 decimal)
16448 / 010 2F CPL ;And its ones-complement
16449 / 4O41 o6 08 LD В,08Н
16451 / 4O43 lF LOOPO RRA ; rotate that
16452 / 4o4k CB 1D RR L ; into L
16454 / 1046 10 ЕВ DJNZ LOOPO ;(FBH - -5 decimal)
16546 / 4048 23 INC HL Ааа one to get twos-complement
16457 / 4049 13 INC DE ;Move DE past the header
16458 / hohA 13 INC DE H of the first variable (the U array)
16459 / 4O4B D5 PUSH DE ; and save two copies
16560 / 404C D5 PUSH DE ; for later use
This should be an array element, and the 16-bit value stored here
should point to the next location where we want to look for DATA. We
copy it into the DE pair.
16461 / 4o4D 1А LD A, (DE) ;Load lo byte
16462 / 4O4E F5 PUSH AF ; and shove it
16463 / 4O4F 13 INC DE
16464 / 4050 1A LD A, (DE) ;Load hi byte
16465 / 4051 F5 PUSH AF ; and move it
16466 / 4052 Di POP DE ; to D
16467 / 4053 Fl POP AF ;Retrieve lo byte
16468 / 4054 06 08 LD B,O8H
16470 / 4056 lF LOOPl RRA z and rotate it
16471 / 4057 CB 1B RR E ; into E
16473 / 4059 10 FB DJNZ LOOP1 ;(FBH = -5 decimal)
Retrieve the array pointer from the stack, add two to it so that it points
to the next element (the flag), copy that into A, and test it. A one indicates
we are ina line of DATA.
16475 / 405B Cl POP BC ;Fop pointer
16476 / %05С 03 INC BC ;Point it to second
16477 / 405D 03 INC BC ; array element
16478 / 4O5E OA LD A,(BC) ;Load flag byte
16479 / hO5F OF RRCA ;Rotate flag into carry—if one, jump
16480 / 4060 38 29 JR C,JUMP2 ;(29H = +41 dicimal) to гей DATA
If flag was zero, search for sequence of letters D-A-T-A. Also test to see that
the search has not gone beyond the end of the program. If past end, leave an
error message and return. If DATA found, change flag to one.
14482 / 4062 13 JUMP1 INC DE ;Move to next location
16483 / 4063 ES PUSH HL ;Subtract address of end of program
16484 / 4o64 19 ADD HL,DE Я by adding its twos-complement
16485 / 4065 El FOF HL : ---ргевегуе HL ir process
16486 / ho66 30 09 JR NC,JUMP2 ;(09Н = +90) Still Ok if no carry
16488 / 4068 02. РОР ЕС ;Else straighten the stack,
16489 / 4069 01 00 3F LD BC, 3FOOH
16492 / hO6C Oh INC B ; leave error message
16493 / hO6D ЗЕ 01 LD А,ОІН s қа one)
16495 / 4COF 02 LD (BC),A Я at hàOOCH,
16496 / 4070 C9 RET 3 and со back
16497 / 4071 1A JUMP2 LD A, (DE) ;Search comes here if still in program
16498 / 4072 FE 29 Cr 29H ;Look for "D"
Location
Decml / Hex
16500 / 4074
16502 / 4076
16503 / 4077
16504 / 4078
16506 / 407A
16508 / 407C
16509 / 407D
16510 / 407E
16512 / 4080
16514 / 4082
16515 / ho83
16516 / 4084
16518 / 4086
16520 / 4088
16522 / 408A
Machine
Language
Labels
Assembly
Language
JR NZ,JUMPl
INC DE
LD A, (DE)
CP 26H
JR N&Z,duMP1
INC DE
LD A, (DE)
CP 39H
JR NZ,JUMPl
INC DE
LD A,(DE)
CP 26H
JR NZ,JUMP1
LD A,O1H
LD (BC),A
Comments
;(ECH = -20D) and go back if not
;Else look next for "А"
;(E6H = -26D) and го back if not
;Else look next for "T"
;(EOH = -32D) and go back if not
;Else next look for "А"
(ПАН = -28D) апа go back if not
;Found? ВС still points to flag in
; user array—change flag
Come here (from either of two places) after deciding that we have a line
of DATA. Put zero in sum—the HL register pair.
16523 / 408B
21 00 OO
JUMP3
LD HL,OOOOH
;oero sum
Get next character. Jump to return routine when comma or End-Of-
Line is found. If itis a number, multiply sum by ten, add number to it, and
come back for next character.
16526 / 408E
16527 / 408F
16528 / 4090
16530 / 4092
16532 / 4094
16534 / 4096
16536 / 4098
16537 / 4099
16529 / 4O9B
16541 / 409D
16543 / hO9F
16545 / ЮА1
16547 / hOA3
16548 / 4oa4
16549 / hOAS5
16550 / hOA6
16551 / ЖА?
16552 / hOA8
16555 / 40a9
16555 / 4OAB
16556 / hOAC
16558 / 4OAE
16560 / hàOBO
16561 / hoBbl
19
DB
J UMP
LOOP2
INC DE
LD A,(DE) ;Load next character
CP D8H ;Check for comma
JR Z,JUMP6 ;(25H = +37 decimal)
LD В,5ВН ;Else put End-Of-Line
RLC B ; into B
CP B 4 and check for it
JR Z,JUMP5 ; (18H = +24 decimal)
SUB 1CH ;Convert it to a number (SUB 28D)
JR C,JUMP4 ;(EFH = -17D) Less than zero? Go back
CP OAH Із it a letter? (Greater than nine?)
JR NC,JUMP4 %(ЕВН = -21 decimal) Then go back
ADD HL,HL ¿Multiplication by ten
PUSH EL ; requires six commands
ADD HL,HL
ADD HL,HL
POP BC
ADD HL,BC
LD B,O8H ;Now rotate
RRA ; latest number into C
RR C A (B will be zero when loops done)
DJNZ LOOP2 ;(FBH = -5 decimal)
ADD HL,BC ;Add it in then go get next character
JR JUMP4 ;(DBH - -27 decimal)
If subroutine comes here, DATA is already in HL register pair. The
return has two parts. The first part changes the flag in the second array
element when an End-Of-Line was found (not a comma).
16563 / hOB3
16564 / 4OB4
16565 / 4OBS5
16566 / 4OB6
16567 / 40B7
16568 / 4OB8
cl
C5
03
05
AF
02
JUMP5
POP BC ;Top stack entry points at first array
PUSH BC ; element. Increment it twice
INC BC : to point at second.
INC BC
XOR A ;Put zero in A
LD (BC),A ; and then in flag.
Second part of return puts address of the End-Of-Line or comma into
first array element and then returns. The triple swap in the first three lines
moves the address of the comma or EOL from DE to the stack and the
address of the first array element from the stack to DE while leaving the
DATA in HL intact.
16569 / hOB9
16570 / 4OBA
16571 / 4OBB
16572 / 4OBC
16575 / hOBD
16574 / 4ORE
16576 / 40CO
16578 / hoc2
16579 / hOC3
16581 / hOC5
16582 / %0С6
16583 / 40c7
16584 / оса
16585 / hOC9
E3
EB
E
Cl
JUMP6
LOOP3
EX (SP) ,HL БАТА, DATA,
EX DE,HL 2 who's got
EX (SP),HL ; the DATA?
POP BC ;Copy lo byte of comma or EOL
PUSH BC е address into C,
LD B,O8H
RR C ; move it
RRA p to A,
DJNZ LOOP3 ;(FBH = -5D)
LD (DE),A j and store it.
POP AF ;Retrieve hi byte
INC DE
LD (DE),A A and store it
RET ¿Return to the BASIC with DATA
34
SYNC Magazine
This line creates an array with two elements
in it, U(0) and U(1). The READ sub uses
both these elements. But there must first
be an array where it expects to find one.
It does not matter what letter the array is
identified by (it does not have to be “U”),
nor does it matter if it has more than two
elements (the extra ones will not be used).
But there must be an array starting at the
very first locations of the space used to
store variables.
Once a variable is created, it will reside
in the user-variables section of RAM until
it is erased by a CLEAR or a RUN. The
rule, except for string variables, is that
the first variable created is in the first
locations of that section. (Strings are erased
from earlier locations and moved to the
end every time they are changed.) The
newest variable always goes to the end of
the file.
Now the user-variables section begins
where the program ends. This means that
the whole section is going to get moved
around. That's right! When you add a
line to your program, it gets longer, and
the Sinclair system knows that it must
move the variables to make room. Likewise,
it moves everything together again, to fill
the gap, when you take a line out.
But do not think that it does all this
blindly. It does not. In fact, it keeps
accurate track of where everything is. It
reserves ten locations, in the lower part
of RAM, to help it do that. Two of these
locations store the low part and the high
part of the address of the beginning of
the first byte OF THE FIRST USER
VARIABLE.
My READ subroutine finds that address,
presumes the first variable is going to be
an array, and goes to the place where the
first element would be (if it actually were
ап array). It expects to find an address
there pointing to the place in the program
where it has to look for more DATA. It
also expects a second element to hold a
flag telling it whether that address is inside
a line of DATA or not. If not, it knows
that it will have to initiate a search for a
place farther down in the program where
the word "DATA" has been typed.
Then, before it returns to execute the
rest of the Basic line, it updates those two
things that it thinks are array elements.
As I said, it only thinks that the array is
in the right spot. It does not do any
checking. The programmer who wants to
use this subroutine is going to have to
make sure that a two-element array gets
placed at the very beginning of the variable
file. This is easy to do. Just make sure
that the first variable created is the needed
array. Then you will know it is in the
beginning. Even though the system will
move the file around as you make your
program larger or smaller, there will always
be a pointer (at locations 16392 and 16393)
to the beginning of the file and thus to the
special array.
November/December 1981
DIMension statements create array type
variables. LET and FOR statements also
create variables some of the time. LET
opens space for simple variables when
they do not already exist. FOR does the
same for the type of variable that controls
a FOR-NEXT loop—it creates one when
it did not exist before.
Thus, if, when the computer is RUN, it
finds the DIMension statement before it
finds any FORs or LETs, I know things
will function correctly. This means that I
make line 2 a DIMension. I could have
added some sort of checking routine, but
that would have lengthened the subroutine.
I would rather put up with the quirk of
having to place the thing properly than to
make it any bigger than it is.
Error Messages
One added feature is a subroutine to
stop the Basic program with an error
message when it runs out of DATA.
The first location in RAM is used as a
mail box for error messages. Each time it
executes a line, the system checks its *mail"
to see if any mistakes were made. If it
finds the number 255 there, it knows
everything is OK and keeps going. If it
finds a number from zero through eight,
however, there was an error. So it Stops
the program, adds one to that number,
and displays it, together with the line
number where the error was found, in the
lower left corner of your TV screen.
The location of the mail box is 4000
hex (or 16384 decimal—see Appendix:
System Memory Locations in your manual
for more details). If. you do not type in
enough DATA, the subroutine will signal
you when it runs out. It will put a 1 in the
mail box and the system will stop the
Basic. That means you will usually see a 2
followed by a colon and the line number
where you were trying to use the USR
function. (I have seen it change to a three
when I was printing an array element in
the same line. For some reason, the system
changed it.)
Getting by Without the “Forbidden
Codes"
The remainder of the article presumes
a knowledge of machine language pro-
gramming, preferably on the Z80.
As noted Part 1, there are many numbers
that cannot be POKEd into line 1 without
messing things up. Those are the numbers
from 40 hex through 7F hex. This restriction
takes certain instructions away from us
outright, and places severe limitations on
our use of other ones. The instructions
that are totally forbidden are the ones
whose machine code number falls in the
forbidden group. The ones that it restricts
are those that sometimes require data in
that range.
1) Forbidden Instructions (Single Op
Code)
The single byte instructions that cannot
be used in this system are transfers from
one register to another within the CPU,
and the transfers between a register and a
memory location when using the HL
register pair as the pointer to that location.
Fortunately, the accumulator (the A
register) can transfer to or from memory
using either the BC pair or the DE pair as
pointers. Those op codes (operation codes)
are not forbidden. They are:
02 for LD (BD),A сору accumulator
into memory at
address in BC;
copy memory at
address in BC into
accumulator;
copy accumulator
into memory at
address in DE; and
copy memory at
address in DE into
accumulator.
OA for LD A,(BC)
12 for LD (DE),A
1A for LD A,(DE)
They work fine. We can use them to get
information between the accumulator and
any memory location in the computer. If
we could find a way to transfer it between
the accumulator and the register that is
to be its destination (or soure), then we
would have it.
We have two ways of working this. If
we want to transfer a value between the
accumulator and the high byte of a register-
pair, we can put it on the stack and take it
off again. For instance, to transfer a value
from A to D, we can put the accumulator
and flags onto the stack and take it off
again into DE.
Example 1.
оооооо[ SeeeceecceceeeeP (SH AF
D1 POP DE
This copies the accumulator into the D
register and the flags into the E register.
Going the other way:
Example 2.
eccces| )5eeeecceeeceeee? | ӨҢ DE
F1 POP AF
copies the D register into the accumulator,
but you should remember that it also
changes the flags. Normal register transfers
do not change the flags.
For other moves we can use the rotate
instructions. One rotate will move a single
bit from one register into the carry flag,
and another rotate will get that bit from
the flag into the other register. Then we
35
repeat that operation seven more times
on the next seven bits, and we have moved
the contents of one register into the other.
Each of the following three examples puts
a copy of the accumulator into the E
register:
Example 3.
0000005 Гееееееееееееееі| [)е A
Example 4.
ееееее()ГееееееееееееФФӨОРБСА
CB 1B RRE
OF RRCA
CB 1B RRE
OF RRCA
CB 1B RR E
OF RRCA
CB 1B RR E
OF RRCA
CB 1B RRE
OF RRCA
CB 1B RR E
OF RRCA
CB 1B RRE
OF RRCA
CB 1B RR E
Example 5.
06 08 LD B,08H
OF LOOP RRCA
CB 1B RR E
10ЕВ DJNZ ГООР
The first example is the most straight
forward. It takes up only one byte of
memory, but its op code could mess us
up.
Example 4, the second one, gets around
that problem, but it requires twenty-four
bytes of storage.
The final example requires only seven
bytes and uses no objectionable op codes.
It uses the DJNZ (Decrement and Jump if
Not Zero) instruction to repeat the instruc-
tions that move the data, one bit at a
time, from the A register, through the
carry, and into the E register. In order to
make the DNJZ instruction work, we must
load the B register with the number eight.
DNJZ decrements B, checks to see if it is
zero, and jumps if it is not. So the loop
will be done eight times. Note that this
method changes both the B register and
the carry flag, so if either holds important
information, you will have to save it and
restore it afterwards.
2) Forbidden Instructions (Multiple Op
Code)
The same restrictions apply to the IX
and IY registers as to the HL pair. You
cannot use them to load the other CPU
registers from memory or vice versa without
using one of these numbers. In fact, the
second op code in an IX or IY instruction
is always the same as the first op code in
the similar HL instruction.
The BIT test instructions are all lost
because of these restrictions, and so are
36
the INput and OUTput instructions that
are distinctive to the Z80. The original
8080 style IN A,(N) and OUT (М),А can
still be used.
The only way that I see to replace the
BIT test is to rotate the bit to be tested
into the carry flag and test the flag. This
changes the register or the memory location
that you rotate, so you may need to copy
the byte into the accumulator and rotate
it instead.
To NEG (negate the accumulator two's
complement style) you must CPL (one's
complement) and then add one:
Example 6.
ееееее Г)еДДееееееееееехЕ(;
is replaced by:
Example 7.
CPL
C6 01 ADD 01H
These two examples leave the same num-
bers in the accumulator, although the flags
will usually be different.
Sixteen-bit subtraction is lost, so when
I needed to do one to find out if the
search for a line of DATA had taken us
beyond the end of the program, I did it
the same way that early programmers had
to do their subtracts. I took the two's
complement of the subtrahend (the number
with the minus in front of it) and I added
that to the minuend (the other one).
There are a few other instructions that
cannot be used, but I had no need for
them, so I did not investigate them. These
include rotates that move a whole digit
(four bits) at a time and transfers to and
from the interrupt (I) register or the refresh
(R) register.
3) Forbidden Data
Early in the subroutine, I wanted to
load 4008 hex into the DE pair. I could
not do that because it would have put a
“40” into my REMark line. I had to put
3F08 hex into DE and increment D.
Later, I wanted to test to see if the
subroutine had just loaded an EOL marker.
That would have meant that it had come
to the end of the line of DATA in the
Basic program. But the Sinclair uses 76
hex (or 118 decimal) as EOL signals and I
could not just write:
Example 6.
ееееееГЕе?беееееееееее(іРТОН
because that would have scrambled things.
So first I figured out that half of 76 hex is
3B hex. I loaded 3B hex into B, I doubled
it by rotating it to the left, and I compared
the contents of the accumulator to it.
Example 9.
06 3B LD B,3BH
CB 00 RLC B
B8 CPB
I cannot call a subroutine that I have
stored somewhere in RAM, and I cannot
jump absolute to any location in RAM
without writing one of these numbers.
RAM begins at 4000 hex and ends at
43FF hex if you have 1K. So the high-
order byte of any address in RAM will be
from 40 hex through 43 hex. When I tell it
to jump absolute or to call, I must give it
an address and that high byte is forbidden.
That will not change if I get 16K because
it will go from 4000 hex through 7FFF
hex. If I find some useful subroutines in
the system ROM (Read Only Memory), I
can call them as long as the low-order
byte is not forbidden. But within any
program that I intend to store in a REMark
line, I am otherwise limited to the relative
style of jump.
The relative jumps are the ones in which
you do not tell it what exact address to go
to, but how many spaces to forward or
backward. The machine takes that number
and the present value of the program
counter, then generates a computed
address, and finally goes to the computed
address. Those of us who learned to write
machine programs on the 6502 or the
6800 had to learn this relative type of
addressing. We could not call if carry or
jump if zero or return if parity odd. We
had a single, unconditional jump, and a
single, unconditional jump to subroutine,
and a single, unconditional return. If we
did not want the instruction to execute
under certain conditions, we would have
to put a branching test ahead of it. Then
we would avoid the instruction entirely
when the conditions were not fulfilled.
We were forced to learn how to compute
a relative jump. Those of you who have
never learned that, can consider this your
big headache or your big opportunity!
4) Computing a Relative Jump.
None of the books listed at the end of
Part 1 really tells you how to figure a
relative jump. So, here goes!
A relative jump can go forward 127
locations or backward 128 locations from
the first byte of the first instruction after
the jump instruction.
When I compute the displacement for
a relative jump, I first leave the space of
one byte after the jump instruction. This
is where the displacement will go. I put
my finger on the byte after that. This is
the first instruction after the jump, and I
call it byte number zero. А common
mistake is to use the jump itself as byte
zero and that will get you in trouble.
SYNC Magazine
The second step is to count the number
of memory locations from there that I
want it to jump when it does jump. (If
that is more than 127 forward or 128
backward, I quit and look for another
method.)
Third, if the jump is forward, I convert
it to hex and that is my relative displace-
ment.
Fourth, if the jump is backward, I
subtract the number I got in the second
step from 256. My displacement will be
the hex version of that difference.
Fifth, I double-check my work by count-
ing the bytes again, usually in hexadecimal
this time. I may also check it by putting
the segment of code into the computer
and running it.
Let's look at a couple of displacements
calculated for the READ subroutine
presented earlier in this article. The first
is a backward jump (Example 10) and the
second is a forward jump (Example 11).
Example 10: Backward Jump
еееее()6 08eccccccecccc[ D BOSH
ОЕ RRCA
CB 1B RRE
10 ?? DJNZ LOOP
2F CPL
In example 10, when the B register
finally decrements to zero, there will be
no more jumps and the next instruction
will be CPL. So I put my finger on the
“2F” and say that it is byte zero.
Second, I count back. The space I have
left for the displacement byte (the “??”) is
number one, “10” is number two, “1B” is
three, “CB” is four, and “OF” is number
five. That is the byte which I want it to do
next when it does jump, so I am done
with step two.
It is a backward jump so step three
does not apply.
Step four is to subtract the number I
got in step two from 256. That leaves me
251. Then I convert it to hex (see below).
That gives me FB. So I take the question
marks out of the displacement byte and
put in “FB”.
Fifth, I put my finger back on the “2F”
which I called byte zero before. This time
I call it byte number FB. Then the dis-
placement byte that I just put in will be
number FC, the “10” is FD, the “1B” is
FE, the “CB” is FF, and the destination
(the “OF”) is byte number 100. That is
what I wanted to see, because I know
that the Z80 CPU is going to do something
November/December 1981
similar and come to the conclusion that it
must execute the “ОЕ” next when it
jumps.
Example 11: Forward Jump
еееееЛ() 22еееееееееә|К NC JUMP2
СІ POP BC
01 00 3F LD BC,3F00H
04 INC B
3E 01 LD A,01H
02 LD (BC),A
C9 RET
1A ЈОМР2 LD A,(DE)
In this case, the ZX80 is to go to the
line marked with the label “JUMP2”
whenever it does jump. How far is that?
Well, for the first step, I know that the
“C1” following the “227 is byte zero. I also
know that the “1A” in the bottom line is
the destination.
So for the second step, we count. “017
is byte one, “00” is two, “ЗЕ” is three,
"04" is four, “3E” is five, “017 is six, “02”
is seven, “C9” is eight, and “1A” is nine.
Nine is the number.
Step three, since nine is the same in
hex as it is in decimal (no conversion is
needed until the number is ten or larger),
I just plug “097 in where I have the 429”,
Step four does not apply, so I check my
work and I am done.
5) Converting Decimal to Hexidecimal
I showed you, in Part 1, that it is easy
to convert from hex to decimal. This time
I need to show you how to go the other
way. But in order to tie it all together, I
will review briefly.
First, remember that there are sixteen
numbers in the hex system:
0, 1, 2,3, 4, 5, 6, 7, 8,9, A, B,C, D,E, &
F
Let’s take the number FB in hex and
find out what it is in decimal. We see that
an F is equal to our number fifteen. Since
every increment in that column is equal
to sixteen in the decimal system, an F
there equals fifteen times sixteen, or 240.
Now the B in the right column is equal to
our eleven, and each increment in that
column is worth only one, so that is eleven
times one, or eleven. Add them together
and we have 251.
(Fx16)+(Bx1)=(15x16)+(11x1)=251
End of review. Now let’s go the other
way —from decimal to hex. If I have a
number small enough to fit into a two
digit hex number after conversion, then I
can make the switch with a single division
by sixteen. (255 is the largest decimal
number that will work.) In example 10, I
ended up needing to convert 251. So I
divided:
251/16 — quotient of 15 and remainder
of 11
Then, if the quotient or the remainder is
ten or more, I substitute the number
between A and F that it corresponds to.
151s the Fth number in the hex sequence,
and 11 is the Bth one. The remainder
goes in the ones column and the quotient
goes in the next (the "sixteens" column.
Therefore, the hex equivalent of 251 will
be FB.
If you want to practice doing a few
jump displacements, you will notice that
in the comments column in Listing 2 I
give every displacement I computed both
in the positive or negative numbers from
the steps two, and in the final hexidecimal
number.
This explanation goes deep enough to
help you convert your jump displacements.
The programming texts that I already
recommended explain the conversion
process in more detail. They will help
you convert larger numbers, like addresses,
if you need to.
Conclusion
This article has covered a lot of ground.
I have given you an implementation of
the standard Basic statement "READ" for
your Sinclair or MicroAce. Part of my
reason for writing this article was to give
you an idea of what it is like to program
in machine language on these machines. I
mainly concentrated on the special tech-
niques needed for that task, and I left
alone the information that is already well
covered in the programming texts.
I hope you have enjoyed it. Good
READing! Good programming. қ,
Blank Cassettes
The quality of cassette tape used to
save and load programs is an important
factor in getting the programs to run.
Tape quality for computers is measured
differently from quality for audio tape.
The tape must be capable of sending to
the computer the electronic signals of
the program without transmitting extra-
neous noises that could interfere with the
ability of the computer to load the tape.
Our blank cassettes are tested and
recommended for computer use. C-10
cassette, 5 min. per side, blank label on
each side in a Norelco hard plastic box.
[0010] $1.25 each.
Head Cleaner
After hours of use, the read/write head in
a cassette recorder will pick up minute
particles of tape oxide. This dirt will hardly
be noticable in dictation or music. But it is
very noticable in computer use. One dropped
bit in 16,000, and the program won t load.
Help keep your recorder in top shape
with our non-abrasive head cleaner. It consists
of 18 inches of stiff cleansing fabric: in a
standard cassette shell. One 10-second pass
every 40 hours of use will keep your heads
as good as new. [0011] $2.00. Send pay-
ment plus $1.00 Shipping per order to:
Peripherals Plus
39 East Hanover Avenue
Morris Plains, NJ 07950
37
zi
-
<<
ж
ToctoctotokokokokokokokRERRR
кк-........-.:
кк........-....
кк-..........
кк............
к............-.
Rubik's Cube has presented puzzle
solvers a most challenging puzzle. and it
raised for me the further question: Was it
possible to simulate on the 2 Х80 at least
some of the features of the cube? In the
first place we have only two dimensions
to work with. We have the limitation of a
4K ROM, а ІК RAM, and a TV screen
for display.
The program below is my attempt, after
many hours of work, to translate the three
dimensional Rubik's Cube to the two
dimensional ТУ screen via the ZX80. The
result, at the editor's suggestion. is
"Hampson's Plane."
After entering the program, which is
rather short, you must take care of a bug
in this way: Press RUN and NEWLINE.
The prompt will call for a skill level entry;
enter 1 and NEWLINE. Wait for the screen
display to appear. Press NEWLINE. The
prompt will ask for a numerical input;
however, enter END and NEWLINE. An
error code will appear. Press NEWLINE
again to get back to program and you are
now ready to start playing. The first thing
to do is save the program. From now on
you must always start with GOTO 1. Never
use RUN or CLEAR.
The gaming board will appear on the
screen. It consists of a board 21 x 15 with
video and inverse video crosses. These
are identified by the use of the coordinates:
letters across the top and numbers down
the left side. Type in the coordinates of
any cross on the board: enter the letter,
M. Hampson, 7 Hereford Drive, Clitheroe, Lancs
BB7 1JP, United Kingdom.
38
++ +
+++
+++
+++
+++
NEWLINE, the number, NEWLINE. The
video display changes, i.e., from normal
to inverse or inverse to normal. That may
sound easy, but there is more. Not only
does that particular cross change, but so
do the surrounding 8 crosses. See Figure
1. The object of the game is to clear the
board completely to normal video crosses.
While that may sound hard, it is possible.
You have your choice of 100 skill levels.
The computer sets out the gaming board
and then sets up the problem by choosing
some random coordinates according to
your skill level. This ensures two things:
first, it is always possible to complete the
Figure 1.
puzzle, and, second, it is only as hard as
you want it to be. While skill level 100 is
very, very hard and can take the best part
of an hour to work out, you always know
that it is possible because the computer
and you got into that mess simply by
typing coordinates. But be warned! It takes
the computer a long time to set up the
board on a high skill level, e.g.. allow 1
min. and 45 sec. on level 100.
2
3
A
3
6
10
15
20
21
22
30
40
50
60
70
80
100
110
120
170
180
1010
1020
1021
1022
1023
1024
1025
1026
1027
1028
1033
+++tt+tt+t++++++++
кк......ш.....-.
RANDOMISE
tt------x«-—-GERx
кк. +++ +
+++ +++ 4+ 4+ +++ + +
+++ ++ ж. .....
PRINT "HAMPSON'S PLANE"
PRINT "ENTER SKILL LEVEL"
INPUT SK
CLS
PRINT ''##ABCDEFGHIJKLMNO"
FOR Z-1 TO 22
IF Z«10 THEN PRINT "0";
PRINT 2; "HAHH";
IF Z<22 THEN PRINT
NEXT Z
FOR L=1 TO SK
LET X=RND(13)+3
LET Y=RND(20)+1
GO SUB 1000
NEXT L
INPUT KS
LET X=CODE (K$)-35
INPUT Y
GO SUB 1000
GO TO 100
FOR Т=1 ТО 9.
THEN
ЕЧ
У}
ынын ны н
" n m m wm "m ww I
О OND Un £P WH HP
ні
B
THEN
LET
LET
LET
LET
LET
LET
LET
LET
LET
Fd "J "JU Y Yyy
=19
Р-17
LET У-РЕЕК(16396)--256%РЕЕК(
16397)
1035 LET N=V+Y*18+X+P
1040 POKE М, PEEK(N)+128
1045 NEXT T
1050 RETURN
SYNC Magazine
A
+
E
T
+++ w
+++ 0
+++ ++ 0
E F
+ +
+ +
+ +
+ +
+ +
4
0
1 +
2 E
3 +
4 4
5 T
6 +
7 +
8
+
+
+
+
+
+
+
+
+
+
+
+
+
ЕЕ
кЕжЖ Ж Ж 2...
ИГЕ,
++t¢et¢¢¢4++4++4+
+
+
+
+
+
-+
+
E
+
4-
+
+
+
+
+
D
+
4
+
+
+
+
ii
+
+
+
+
+
+
+.
+
+
+
+
4
+
--
+
>
кк... ++ +
кк - - —-G c--4-mBBx
кк...
++teette+e+et+t
++teett¢eret+tt
++++++++++++
+++tt+t++t++++++
++teetter+rtt+tet
+
+
+
+
4-
+
Ez
+
+
-H
+
+
E
+
-+
ы
+
+ =
If you have expansion memory, you
can do the de-bugging in this way: Set up
a flag F thus:
1 LET F=1
Then insert the program alteration which
is only required once before the display
file has adjusted its position:
1036 IF F THEN LET N=N+6
And finally reset the flag F:
1037 LET F=0
You can now use RUN instead of GOTO
1.
Sample Run
Type GOTO 1
HAMPSON'S PLANE
ENTER SKILL LEVEL
Enter 7 and wait for the display.
The obvious moves are B,5; F,8; N.9 and
J,21. But we are left with a muddle at the
top. The solution is 1,3, K,2, M,3. Now to
return to command mode, type NEWLINE,
END, NEWLINE. Now try a high skill
level. This may keep you going as long as
the original cube! So I suggest building
up slowly, learning the tricks as you go
along. A good plan is to raise your skill
level by fives each time you run the pro-
gram.
The best of British luck! a"
MX16-16K RAM
FOR USE WITH THE
SINCLAIR 7Х809
RAM MODULE
AND
POWER SUPPLY
$89.95 PLUS
$3.00 SHIPPING
AND HANDLING
INSIGHT
1889 LEWIS DRIVE
NILES, MICHIGAN 49120
616-684-7868
M.C./CHECK/M.O./VISA/C.O.D.
November/December 1981
CON DU KF WN н
ЯР
+t+t+tt+t+t+t+t+tt+tt+t+t++t+t+t++++++ >
кк а-а-а. ....4 w
+t+tt+tt+t+++t+tt+tt+t+t+t+t+++++++Ł4 с
кк ы RR x RRcR4àRR RW
++eteteetteetteeete+r+t+et+tet+ n
+eteteetteeteererteert+et+tt+et+ H
+tt+t+t+t++t++t+t+++++++ł+++++ a
Keyboard Sounders
Every keyboard entry gives
you a short audible bleep.
KS1 for ZX80
KS2 for ZX81
Tape Recorder Interface.
Gives adequate level for
loading from cassette
machines.
T.R.l. for ZX80/81
Video Amplifier Unit
Will drive standard 1 volt
monitors.
V.A.U. for ZX80/81 .£12
Complete with leads and diagrams.
Connections only take a few minutes. p-p. sop
D. BRUCE ELECTRONICS
E E į
++etetetteeeteeeteetet+ttit+ =
+t+t+t+t+t++++t+t+tt+t++++++
HARDWARE
£12
THE BEACON BLACKHALL ROCKS
Tel: 0783-863612
CLEVELAND TS27 4BH
+++++++++++++++++++
++++tt+t+t++++++t+t+++++
кк...
E о
кЕ5-..............
39
8K ROM
IK RAM
Ever since seeing the Artillery game in the March/April
issue of SYNC, I have been interested in devising a way for
the player to see the projectile on its flight to the target, using
the 8K ROM, of course. It would be an easy project with lots
of RAM, but it was not that easy when limited to IK RAM.
After rewriting much of the program to save space and
eliminating a few features such as keeping track of the number
of shells fired, I was finally able to make it work.
To play the game, RUN the program. Make your first shot
by ENTERing any angle of elevation between 0 and 90 degrees.
At the higher angles, you will see the shell arch way up before
falling back to the ground, much like a mortar shell being
“lobbed” toward its target. Continue firing until you get a
direct hit. Then the game is over. You can count your shots
from the shell holes in the display. Hit RUN to start over.
A few notes will make the program clearer:
1) Listing 2: l. 12, INPUT is a key word.
2) Listing 2: If you encounter memory problems, omit lines 1,
2, 12, 38, but you must remember what the game calls for «
without the screen prompts.
3) Listing 2:1. 38, Direct hit must be followed by 5 spaces and
the * mark.
4) Both versions: 8, inverse 0, 30 graphic D
32, asterisk
36, inverse asterisk is a hit.
5) Both versions show the projectile; the ZX80 by a PAUSE
routine, and the ZX81 by the SLOW mode. и,
Chuck Dawson, 6520 Victoria, Fort Worth, TX 76118. Program adapted
to ZX81 by David Grosjean.
ZX81 owners
have you seen
The Cambridge Collection
A book of
30 PROGRAMS
For Only £4.95
NO MEMORY EXPANSION NEEDED
Each program has been designed to fit into 1K of RAM
TEACH YOURSELF PROGRAMMING
Comprehensive explanations of each listing will teach
you many techniques of ZX81 programming.
HOURS OF AMUSEMENT
With titles such as FORTRESS, BALLOON, and ODD MAN
OUT, you could easily become a ZX81 addict. Plus,
entirely new implementations of well-known favourites:
LUNAR LANDING, MASTER CODE, ORBITAL INVADERS,
and many others.
CASSETTE AVAILABLE TOO!
If you order the book you can also buy the
programs on a quality cassette for only
£4.95 extra.
; Ref. 1
Please send me: Please send your orders
with cheques/PO's to:
Richard Francis,
22 Foxhollow, Barhill,
Cambridge, CB3 8EP.
copies of the book at
£4.95 each
copies of the book and
cassette at £9.90 pair
Artillery with Motion
урны |
RISO Ф 9 С Ф.н
Lt) GJ 0910 fO fO TO
Que fo 6 09 7-4 O1 T
Chuck Dawson
Listing 1. ZX80 8K ROM
REM 2хзе |
REM “ARTILLERY”
LET B-1G2INT (RND#20) —
PRINT “RANGE="; N; “gga YDS
PRINT HT 17,U; и ХМАРНА
AE
PRINT AF IFR; "TT"
INPUT М
LET
THEN LET N=28-N
LET LzINT (Nx#.68)
FOR Ісі TO 2x*L-1
LET «-ісз-е-Бузжсінм
PLOT I,
PRUSE аа
PORE Lodar,255
UNPLOT I.
NEXT I
PRINT HT 17,L; "3"
IF Riol THEN GOTO
PRINT HT 1FL; ЕЗ"
О-У р р.
ia
Listing 2. ZX81 SLOW Mode
D o P TOP
ZXB81
“ARTILLERY”
LET H-182INT (RND#20})
PRINT “RANGE="; 8; "@e@a YDS"
PRINT AT i7,.u: кл ----------
SS
Ta R; "PU
INPUT ELEVATION"
REM
КЕМ
BIN
IF М>45 THEN LET N=98-N
LET L-INT (NJ. GS)?
FOR Ісі ТО 2xL-i
dzlCÀ -B.GSIN
=
IF Ві». THEN GOTO 14
PRINT HT 17.L;: "EX- .
PRINT “DIRECT HIT i
Sample Run
RANGE =11000 YDS
hasse Fanaa ET 8
INPUT ELEURTION
NNN F AN RU RE
4K ROM
IK RAM
"You Are in a Maze..."
Gary McGath
“Of twisty little passages, all alike."
This message, in Adventure of Zork, tells
you that you have embarked on one of
the most challenging phases of the game:
mapping the maze and finding your way
out. Even without the rest of the dungeon,
a maze can make an exciting puzzle in
itself — especially if there is a hungry dragon
wandering through the maze looking for
you.
The “Maze” program runs on the min-
imal ZX80 with ІК RAM. Each room of
the maze has three doors leading to other
rooms, or to freedom. The rooms are
numbered, and you know which room
you are in by the number that is displayed
on the screen. You start off in room 1,
just as the dragon is coming in through
the exit. If the dragon is in an adjacent
room, you can hear it.
You move by entering a 1, 2, or 3 to
pick one of the doors, or you can stay
where you are by typing a zero. The dragon
always moves after you. If you should
meet the dragon, you become his dinner.
5 RANDOMISE
10 DIM A(14)
20 DIM B(16)
30 DIM C(16&)
40 FOR I = 1 TO 16
50 LET А1) = 0
60 LET B(I) = 0
70 LET C(I) = OQ
80 NEXT I
90 FOR I - 1 TO 16
100 IF А(12>0 THEN GO TO 140
110 GOSUB 800
130 IF NOT N-I THEN
LET А(19-М
140 IF B(I)50 THEN GO TO 170
150 GOSUB 800
160 IF NOT N=I THEN
LET B(J)=N
170 IF C(I)>0 THEN GO TO 200
180 GOSUB 800
190 IF NOT N=I THEN LET
CCIOZN
200 NEXT I
300 LET U=1
315 LET Z=RND(15) +1
316 LET D-Z
320 CLS
330 PRINT U
350 IF NOT(D=ACU) OR D-B(U)
OR D=CCU)) THEN GO TO 380
November/December 1981
To win, you must find an exit before the
dragon finds you.
A couple of pointers: (1) Since the
dragon moves after you, you may both
walk into the same room without your
having previously heard the dragon. Thus,
you can get eaten without warning. (2) It
is not cheating to study the maze generation
part of the program for any peculiarities
that might help you. For example, it turns
out that lower numbered doors tend to
lead to lower numbered rooms. (3) Col-
lectors of programming tricks should note
the use of the “computed GO TO” in
statement 450, in which the next statement
executed is determined by a random
number. This capability is a feature of
ZX80 Basic and does not exist on many
other Basics.
May you always elude the dragon in
your wanderings. "n
Gary McGath, 5 Ames Rd., RFD £3, Milford, NH
03055.
360 PRINT "YOU HEAR THE
DRAGON”
INPUT X
IF X=) THEN
=2 THEN
Х=3 THEN
380
400
410
420
430
440
450
900
210
we
230
240
250
600
LET Ue CU)
LET О-Н CU)
LET UC qu)
Мер THEN GO TO 600
U-Z THEN GO TO 700
GO TO 480+(208RND (3) >
LET D=ACD)
GO TO 550
LET D=B(D)
GO TO 550
LET D=C(D)
IF NOT U-D THEN GO TO 320
PRINT "THE DRAGON CAUGHT
YOU"
STOP
PRINT
STOP
LET N=RND(16)
IF ACN)-O THEN GO TO 840
IF B(N):O THEN GO TO 870
IF C(N)=0 THEN GO TO 930
GO TO 800
LET АМ) «I
RETURN
LET B(N)-T
RETURN
LET C(N)=I1
RETURN
610
700
710
800
810
830
840
850
860
870
890
900
930
940
"YOU GOT AWAY"
ZX80/81 DATABASE
HAVEN HARDWARE
ZX80 & ZX81 ADD ONS
PROGRAMMABLE CHARACTER
GENERATOR, KIT £22.50
BUILT £29.95
(SUPERBOARD/U.K.10£39.95)
1-3K MEMORY EXPANSION
(INCLUDES 1K) KIT £9.95
REPEATING KEY-MODULE
KIT £1.95 BUILT£2.50
KEY BOARD KIT £17.50
COLOR BOARD APPROX £40
PRICE IN $ = 1.5 X PRICE IN £ SAE
FOR DETAILS SHEET
HAVEN HARDWARE
4 ASBY ROAD
ASBY WORKINGTON
CUMBRIA ENGLAND
For serious 8K ROM/16 RAM users,
DATABASE blends Basic menus with over
1K m/c logic to give dynamic file of
name/address/interest codes/text. Select-
able display formats include address labels
for printing. Search any element type by
any key. Beautiful to use, and very fast.
All file data is packed into a single string
whose length is automatically altered for O
to 500+ entries. Tape and full document-
атіоп.... £10.
SAE for full catalogue of Action games,
Magic Cube, Disassemblers. . for 4K or 8K
ROM,Sinclairs.
CAMPBELL SYSTEMS dept SY, 15
Rous Rd, Buckhurst Hill, Essex 1G9 6BL.
FREE
48-Page
Catalog
A new, free 48-page catalog is free
from Creative Computing and Periph-
erals Plus. To help buyers make intelli-
gent purchasing decisions, the product
descriptions are exceptionally compre-
hensive and include screen photos in the
software section.
The catalog describes 20 books on pro-
gramming, games, and educational appli-
cations; 160 software packages for
Apple, Atari, TRS-80, PET, CP/M, TI, Sor-
cerer and Sol computers; 3 magazines
(Creative Computing, Microsystems, and
SYNC); 5 graphics and music peripherals;
an LP record; board game; 8 T-shirts and
an eclectic assortment of other products
for the personal computer user.
To get your free copy, simply drop a
card or note to the address below.
creative
corpatirg
39 East Hanover Avenue
Morris Plains, NU 07960
41
The Hidden Chessmen is a search and
find game like Hurkle (SYNC 1:1, p. 12).
A knight, a bishop, and a rook are hidden
on a chessboard by the computer. You
begin the play by guessing a square on
the chessboard. The computer tells you if
you have found a chess piece and/or what
pieces are attacking the square. From
this information you deduce your next
guess, and eventually the locations of the
three pieces.
In this game no two pieces can be on
the same square. The pieces attack in the
normal chess fashion, except that an
intervening piece does not block the attack
of the bishop or rook.
You enter your guess by entering the
square's coordinates consecutively without
a space, comma, or NEWLINE between
them. The first number is across, the second
down. This means that the upper left square
is 11 (one across, one down), the upper
right is 81, the lower left is 18, and the
lower right is 88. Pressing NEWLINE enters
the guess. Guesses off the chessboard are
rejected (so you would get no response
for a guess such as 03) but they are tallied
in the running total of the number of
guesses made.
Each individual square of the chessboard
is made up of four character display
squares. For the purpose of explanation
these numbered 1--4 in the diagram.
If no chess piece is at the position guessed,
a 0 will appear in square 1 of that position.
Roger and Susan Haar, 19372 Holts East Rd.,
Martin, OH 43445.
42
The Hidden Chessmen
Roger and Susan Haar
But if a piece is at the guessed position a
B, K, or R will appear in square 1 repre-
senting the bishop, knight, or rook respec-
tively. In display squares 2, 3, and 4 a B,
K, or R will appear if the corresponding
piece is attacking the chosen square.
For example, if you had entered 46, the
square 4 across and 6 down on the chess-
board might appear as:
The 0 means that no piece is on square
46, but the B and R mean that both the
bishop and the rook are attacking square
46.
A guess of 35 might give:
No piece is attacking the square, but you
have found the bishop!
After four guesses — 46, 35, 16, 78—the
screen might show a display such as Figure
Figure 1.
The program does not tell you when
you have found all three pieces. When
you believe you have found all the chess-
men ог have given up, you can enter 0 as
your guess. The location of the pieces
and the number of guesses you made will
appear below the normal display. If after
the four moves made in the above example
you entered a zero, the following would
be added to the display:
B35 K81 R16
4 Guess
The program uses all of the ІК ZX80
memory. To conserve memory, we used
all the one digit line numbers (1-9) and
then only the two digit line numbers (10-
99). This does not save in the line number-
ing, but in the GOTO lines we save 5
bytes.
More memory space was saved by
switching from two character variable
names like B1 and B2 to one character
names such as B and C. This saved another
40 bytes.
The computer saves the value of vari-
ables in the variable section of its memory.
To save more space, we reused the names
of some variables: X and Y from the
PRINTing routine, and Q from the INPUT-
ting routine. This lets the computer forget
information no longer useful and remember
new data in its place.
When a variable is first used, it is given
a spot in the variable storage and this
moves the memory location of the display
file. A problem would occur if Q had not
been used before line 50 where the start
of the display file is found by PEEKing. A
memory location for Q would have been
made after the PEEKing. The display file
is not where your program thinks it is.
This would mess up the information
POKEd onto the board by the first guess
(and could be a problem in similar pro-
grams).
POKEing into the display file creates
one other problem: it is easy to remove a
line delimiter (code 118). This can produce
lines longer than 32 characters which crash
the program. Unplugging the computer
seems to be the only solution. Before
running a new program which includes
POKEing into the display file, you should
save it. This avoids retyping all of the
program should it crash. Also beware of a
POKEing mistake that changes the pro-
gram.
SYNC Magazine
The Hidden Chessmen
Program Listing
1 LET B=RND 3)
© LET C=RND (8)
4 LET K=RND 8)
4 LET L:RMDGCBD
2 IF EB AND L=C THEN GOTO 3
ó LET R=RND (E)
7 LET S=RNG (8)
g IF Кен AND S=C ОЕ
=.) THEN GOTO 6
(Rk AND 5
9 LET Мед
10 FOR Х=1 TO 4
12 FÜR Y=1 TO 2
14 PRINT "ААЖВААВВаАЯ ВАА"
16 NEXT Y
18 FOR Y=]
ео PRINT
21 NEXT Y
22 NEXT X
20 [RINT
S2 PRINT
A4 PRINT
до INFUT G
42 IF @=0 THEN GOTO 90
2 LET N=N+i
44 LET X-Q/io
46 LET Үш -10жХ
48 IF Х<1 OR Yel
8 THEN GOTO 40
YO LET G=FEER (19296) 25 ӘЖРЕЕК ¢
193597)-2*XX—-1lc-x4*X0CY-1)
we PORE 0,29
34 IF ХаВ AND Y=C THEN FOKE 0,
ao
ЗО IF ХшҚ
TŪ F
"ABRAORHEOOR EGGS"
DN?"
"ACR;
OR X28 OR Ys
AND YsL THEN FORE 0,
48
SB IF ХаН AND Y=S THEN РОКЕ 0,
55
60 IF ABS (X-E)=ABSCY-C) AND NO
T (ХеВ) THEN FOKE 041,59
ӨЗ IF ABS(X-K)=1 AND ABSG(-L)s
2 OR (ABS (X%-k)=2 AND
ABS (Y-L)=1) THEN FOKE 0-17, 48
64 IF (XsR OR Y=S) AND NOT (x=
R AND Y=S) THEN PORE (818, 55
66 GOTO 40
90 PRINT "EB"iBi"B"iC, YEA ks
H's, URE Rs eG
92 PRINT Ns; 4GUESS"
Variables List
B,C; K,L; R,S — Chess piece coordi-
nates
X,Y — FOR NEXT variables; later
coordinates of guess.
Q — INPUT variable; later location of
the guessed chess square in the display
file.
N — number of guesses.
Program Summary
Lines 1-8 place the chess pieces.
Line 9 sets guess counter to zero.
Lines 10-34 print the chess board.
Lines 40-48 input guess and process it.
Lines 50-64 put information about
guessed square onto the displayed chess-
board.
Line 66 returns to input.
Lines 90-92 print the piece location and
number of guesses. n"
November/December 1981
The most complex computer circuit can be
explained with just nine cents
Common
Cents
The "penny switch." It sounds strange.
But it's not.
Joe Weisbecker, the designer of the RCA
1802 microcomputer, was trying to explain
to some children just how a computer works.
He wasn't having much success.
Computers Aren't Magic
Joe's hobby is magic. He thought, “таубе
| can use some kind of illusion to show how
a computer works." But he didn't really want
to use an illusion. He didn't want the chil-
dren to think of a computer as magic.
So he hit upon the idea of a simple flip-
flop switch (the most common circuit in a
computer) represented by the head or tail
of a penny. This flip-flop circuit uses just
one penny. Every time it receives an impulse
it changes from head to tail or tail to head.
Simple.
But then Joe went on and put two of
these simple flip flops together to make a
circuit that adds two numbers together. And
another that subtracts numbers. Kids loved
these circuits and played with them like
games.
Games With Pennies
Before long, Joe devised circuits to play
more complicated games like Tic Tac Toe,
"Heads Up Game." Starting with tails in all
positions, how many times through to get
all four pennies heads up?
Guess A Number and Create A Pattern.
Pretty soon he had 30 circuits (or games)
that explained everything about computers
from a basic adder to complex error correc-
tion. The most complex circuit uses just
nine pennies (or dimes for the big spender).
These circuits, each one with a full size
playing diagram, have been collected to-
gether in a book called Computer Coin
Games. With this book children or adults
can easily understand the workings of even
the most complex computer circuits.
Games Magazine said, "whether or not
you have any experience with computer
technology, you'll be both amazed and de-
lighted with the simplicity of the format and
the complexity of the play. All you need is
some common cents.”
Dr. Dobbs Journal agreed, saying, “Сот-
puter Coin Games is a simple approach to a
complicated concept. The book is liberally
sprinkled with clever illustrations and dia-
grams, and provides a relatively painless
route to understanding how computer cir-
cuits function."
Money back Guarantee
We're convinced that you'll understand
the inner workings of a computer after playing
these 30 games. If you don t, send the book
back and we'll refund the complete price
plus your postage to send it back.
To order your copy of Computer Coin
Games, just send $3.95 plus $2.00 for one,
$3.00 for two or more for shipping and
handling to Creative Computing Press,
Morris Plains, NJ 07950. Visa, MasterCard
and American Expess orders may be
called toll free to 800-631-8112 (in NJ,
201-540-0445).
With its wonderful illustrations by Sunstone
Graphics, Computer Coin Games makesan
ideal gift. The Association for Educational
Data Systems calls the book "an ideal intro-
duction to the concepts of computer
circuitry."
Order your copy today.
creative
competing
Morris Plains, NJ 07950
Toll-free 800-631-8112
(In NJ 201-540-0445)
43
4K ROM
2K RAM
Judging from the many books on word
search (or "find a word") puzzles available
at any newsstand, these puzzles must be
popular. To save some money, you can
create your own puzzles rather than buy
the puzzle books. But, if you create your
own manually, you know where the words
are so itis not much fun. There is another
way. By using this program in the Z X80
or MicroAce, you can create your own
15- by 11-character word puzzles and have
fun solving them or give them to your
friends to solve.
The program requires 2K of memory
to run and just barely fits into that. So
changes to the program that you may
want to make must not increase its size if
you have only 2K.
When the program is run, the following
is displayed.
CREATE A WORD SEARCH
PUZZLE
ENTER WORDS OF UP TO 11
LETTERS EACH
FIRST WORD? NULL ENTRY TO
END.
The first word is keyed in, followed by
NEWLINE. The program responds in one
of four ways to each word entered.
Bill McCray. 577 Bellcastle Road. Lexington. K Y
40505.
keoshyeluncgjhpwsmxreoap
ahtyvpkwqhdxmzpruekfnhw
Create a Word Search Puzzle
aewpnfywvisyeondqixhurpm
idgaewmbpjdzaugofnepkuyt
Bill McCray
1. “word entered”
NEXT WORD? NULL ENTRY TO
END.
The program has successfully embedded
the word and wants another.
2. “word entered”
WORD DOES NOT FIT
NEXT WORD? NULL ENTRY TO
END.
The program was unable to embed the
word. Although the puzzle is getting full,
another word may fit.
3. “word entered”
TOO MANY LETTERS
REENTER
The word entered is longer than 11 letters.
Try another.
4. “word entered”
INVALID CHARACTER
REENTER
Entering E and NEWLINE ends the pro-
gram and returns to the Basic mode.
Entering S and NEWLINE prints the
solution to the puzzle. P and NEWLINE
or any other entry prints the puzzle
As an example, the following Basic words
were entered into the program.
U I L Q C R V B H R
O T M S N Y C T G F
(SOLUTION, (P)UZZLE, OR (E)ND?
Figure 1.
44
ҚК E D J T P Q
N B L B U
E U D H D P V
H 5 O X A E N
T O С B O I
The word entered contains a character
other than a letter. Reenter it correctly.
After all words have been entered or
the program appears to be unable to embed
any more words, a null entry (NEWLINE
only) ends the entry and puzzle-construc-
tion phase.
The output phase asks the user to select
among three options by printing
(SOLUTION, (P)UZZLE, OR (E)ND?
CLEAR NEW
CLS NEXT
CONTINUE POKE
DIM PRINT
FOR RANDOMISE
GOSUB REMARK
GOTO RETURN
IFTHEN RUN
INPUT SAVE
LET STOP
LIST
LOAD
The puzzle listing generated by P and
NEWLINE is seen in Figure 1.
The listing contains the embedded letters
and randomly-generated letters in all
unused positions.
I G R N B
M R O F I E U
O R T R N H 5
D E E O S T O
N L T M L F G
A U C A C I
R . R
K
Figure 2.
. SYNC Magazine
Program Listing
10 DIM А(164)
20 DIM B(10)
40 RANDOMISE
50 FOR I-O TO 164
60 LET А(1) =0
70 NEXT I
If the program is able to embed all but маталы ENTE A MENSE ЖЕЛКЕН
At this point the user сап сору the а small number of the words desired, 90 PRINT
puzzle onto paper. The output options running the program again may allow the ies dapi edi WORDS OF UF TO
are listed at the bottom forselection. The — entire list to be embedded, since random- 110 PRINT "EACH"
selected letter does not show on the display — ness is used in the embedding process. een dap еліккен
when it is entered, but it is still input. 140 PRINT АФ; " WORD? NULL
If SOLUTION is selected, the same Algorithm _ ENTRY TO END."
TE А А . 150 INFUT АФ
listing is generated, but periods are sub- А word may be embedded in any of 160 CLS
stituted for the randomly-generated letters eight orientations, corresponding to the e a Lt THEN GO TO 800
А e_o А ee s . О Е í $
in the unused positions. The solution listing eight points of the compass. One of these 200 POR еб TG 16
for the puzzle in Figure 1 is shown in directions is chosen randomly. АП possible 210 LET B(C)-CODE(A$) -
Figure 2. locations for the word in that orientation ee Ara
The solution and puzzle may be listed are checked. The location giving the 240 IF AS="" THEN GO TO 210
. . . . E unl xd
as many times as desired until Eisselected. greatest degree of overlap with the pre- o —A
Each time P is selected, the randomly- viously positioned words is chosen. If no 270 PRINT "REENTER"
generated letters change. The embedded overlap is possible, the word may be E UL MM
letters, of course, are unchanged. embedded without overlap, if there is space 300 GO TO 270
open yet. If the word cannot be placed in EU es tie
" қ " X20 г zi)
Hints for Users the selected orientation, the other seven 550 FOR I=1 TO RND(8)
Long words should be entered first. Since orientations are investigated in turn in ”
. e è Я 550 І
more of the spaces аге unoccupied, ће the same manner until embedding is ety LET А-1
chances of successful embedding are accomplished or is found to be impos- 370 FOR I-1 TO 8
improved. sible. CHE (202
400 LET E-1S*CX (050)
410 LET F=-Cx (V0)
420 LET G-11*CX (V0)
420 LET XzRHND(E-D)-*D-1
е 440 LET Y=RND(G-F)+F-1
Variables 450 FOR J=1 TO (E-D) *(G-F)
A array Contents of the puzzle locations. 460 LET X-X«1 EM
B array Letters of the word to be embedded. 4...”
AS General character variable, many uses. 490 LET Y=Y+1
A Overlap level attained. М... er
B Overlap counter for position being investigated. 515 LET M=X+15xY
C Length - 1 of the word to be embedded. 422...
D-G Horizontal and vertical limits of the possible starting positions 540 LET M=M+W
ы : 2 : Ы 960 IF L=0 THEN GO TO 590
for the orientation being investigated. езгіге QU TE Aid
І-М General and loop variables. 580 LET B-B«1
P Starting location for the word position giving the overlap doc E M
4 : 600 IF NOT EA THEN GO TO 660
level given in A. 610 LET А-В
Q Letter displacement for the word position starting in P. 620 LET Р=Х+15жҮ
А А А Е А 640 LET Q=W
U-V Horizontal and vertical displacements for the orientation 660 NEXT J
being investigated. 665 IF А>-1 THEN GO TO 700
. . 670 NEXT I
W Sum of U and V; the total displacement. | 7 LH PRINT “WORE. DOES NOT FET
X - Y Horizontal and vertical position of the starting position 690 GO TO 780
1 : : 700 FOR к-о TO C
being investigated. 750 LET A(F)sB(E)
755 LET F-zF-«Q
760 NEXT E
780 LET A$-"NEXT"
Program Notes 790 GO TO 140
10-130 Initialize the program and give the first output. ME erum e c DM NES,
140-180 Get a word and output it. 810 ‘INPUT A$
200-300 Test the word for validity. 815 IF A$-"E" THEN LIST
310-350 Select an orientation randomly. ESTE mus
360-670 Test a possible embedding position. 840 FOR К=0 TO 10
ее ‘ 850 FOR 4-0 TO 14
360 Initializes the overlap level attained. өзі LET bend
380 Changes the orientation. 852 IF L THEN GO TO 880
390-420 Calculate the X and Y limits for the orientation. ы Pussy екі
430-440 Select a location within the limits randomly. L=RND (26) +37
460-500 Move to the next location. о NT LS
А = B90 LET I=I+1
520-590 See if the word fits here. 900 NEXT J
580 Increment overlap counter if a matching letter is found. 910 PRINT
А ... 920 PRINT
600-640 If greater overlapping found, save the level and position. 9z0 NEXT К
655 Embedding possible in this orientation? 2 ae pes Р —Q
50 = (0>-1) ж (35-1) - (01) 4
700-760 Embed word. 960 LET V-1S5X (Uc 1) X (V;—-1) - (02-1)
780-790 Go to get another word. (OX (ID)
800-940 Output results. 2141.
950-990 Subroutine to change orientation. 990 RETURN
November/December 1981
4K ROM
ІК RAM
Two lonas of Taxman
Taxman has been my favorite mathe-
matical computer game since I first dis-
covered it in the Apple Pi program library
more than two years ago. (Apple Pi is the
Denver area Apple users group.) Taxman
is a challenging game to play. With the
advent of the ZX80 came a further chal-
lenge: could Taxman be adapted from a
"large" computer (Apple II) to a really
small computer, the Sinclair ZX80?
Was the second challenge met? The
answer is a qualified "Yes". Here is a
complete program for Taxman, reduced
in size from 50 maximum to 30 maximum.
Some of the nicities of user interaction
are gone, but I believe that ZX80 Taxman
still is an interesting, challenging game.
Before looking at the program and its
lessons in compacting large programs for
the ZX80, let's play the game.
The Game
The computer will lay out the integers
from 1 to a maximum which you have
entered. You pick one of these numbers;
Taxman gets all the remaining factors of
that number. If there are no remaining
factors of the number chosen, you cannot
have it. When there are no remaining
factors of any unchosen number, the game
is over; and Taxman gets the remaining
numbers. If the sum of your chosen
numbers is greater than the sum of Taxman,
you win.
Let's play a simple game. First enter or
LOAD the program, then RUN.
TAXMAN
YOU GET NUMBER; I GET FACTORS
Austin R. Brown, Jr., 407 Peery Parkway, Golden,
CO 80401.
46
Austin R. Brown, Jr.
This is the abbreviated introductory
message.
HOW MANY(30 MAX)?
Here you choose the size of the game;
let's choose 12.
123456789 1011 12
PICK A NUMBER
Let’s pick 12.
YOU GET 12
IGET 12346
SCORE- YOU:12 ME:16
57891011
PICK A NUMBER
Taxman took all the factors of 12, which
added up to 16. Now from the remaining
numbers let’s pick 11.
NO FACTOR FOR ME,
TRY AGAIN.
57891011
PICK A NUMBER
The only factor of 11 is 1. It is already
gone. Since Taxman must always get some-
thing, we cannot choose 11. Let's try 10.
YOU GET 10
I| GET 5
SCORE- YOU:22 ME:21
78911
DONE
I GET789 11
FINAL SCORE- YOU:22 ME:56
Since no factors remained for any remain-
ing numbers, the game is over and the
Taxman gets the balance, and Taxman
wins.
Can Taxman be beaten? Play again with
12. This time start by picking 11, then 4,
etc. It is not easy, but you can beat the
Taxman.
The Program
Among the factors involved in writing
an interactive program are personalization,
on-line documentation, and interaction.
What does Taxman teach us about these
factors in the severely restricted environ-
ment of the 1K Sinclair ZX80?
Personalization is that aspect of an
interactive program which starts with
WHAT IS YOUR NAME?, then goes on
to PICK A NUMBER, BOB, encourages
with TERRIFIC, BOB!, chastises with
COME NOW, BOB, etc. In many programs
it is a frill rather than a part of the essence
of the program. Out it goes! With less
than 1024 bytes at our disposal, we cannot
afford the space. But wait until 16K
memory arrives; personalization will be
back.
On-line documentation consists of the
information the program gives us about
itself while it is running. Ideally, this should
include everything we need to know to
run the program; no external manual or
other printed instructions should be needed.
The realities of a 1K byte machine take
us a long way from the ideal. Sometimes,
as in Acey Ducey (SYNC 1:16), no instruc-
tions are given. If possible, a program
should at least include its name and one
line of description or instruction (lines
20-30 of the program).
However, adding text to а ZX80 program
can cause additional complications. Most
video-oriented personal computers reserve
a fixed block of memory for display; the
ZX80 does not (ZX80 Operating Manual,
SYNC Magazine
p. 108). Therefore, if text is added which
increases the maximum size of the display
of a ZX80 program, the program may
bomb with error code 4, even though the
program itself will fit in memory. For
example, run Taxman with 30 numbers,
picking successively 24, 30, 14, 27, 26, 22.
Now add line 605 PRINT and rerun with
the same pattern. There is no longer room
for the last few characters in the final
display, hence the error ending.
Most interesting or useful programs for
personal computers are interactive; they
require some response from the user,
whether data or decisions. The user must
know what is expected when it is time for
input; there is nothing as frustrating as an
isolated question mark, much less only
the cursor leaving you to wonder, “What
do I do now?" Give as much information
in the questions as possible. Lines 110
and 200 are much clearer than they would
be if they said, "SIZE?" and “PICK.”
Ideally, any interactive program should
maintain complete control over input, so
that it is impossible to make an incorrect
response. There is not much room for
input control in ІК machine. The ZX80
helps us with the LS cursor when a number
Is expected. We can also check for range,
as in lines 130 and 230. But what happens
if zero or a negative number had been
given for the game size? Would it have
been better to cut the maximum size of
the game in order to have more complete
error checking?
Every program should have good logic
and be written in an understandable way.
One of the virtues of a tiny computer is
that it forces the programmer to learn to
write efficient programs if the program is
to do anything significant. Efficient logic
is not always clear logic. REMarks are
important for clarity. However, REMarks
take up space. One common solution is
to have two versions of a program, one
with REMarks for the human and one
without for the computer. Note in the
listing that all REMarks have line numbers
ending in 5. These can be eliminated from
the running version of the program if you
have a IK RAM or if you do not want to
enter them.
November/December 1981
Lines 240-350 give another lesson from
laxman about ZX80 programming. The
ZX80 displays output on the TV screen
only when all computation is completed.
This is usually considered a disadvantage;
it can be turned to an advantage when a
given display may or may not be wanted.
The display of the division of the spoils is
always started. If there are no factors for
Taxman, line 350 sends control to line
800, where the display is cleared before it
Is ever seen.
5 REM taxman for ZX80
10 DIM F(30)
15 REM introduction
20 PRINT "TAXMAN"
30 PRINT "YOU GET NUMBER; I GE
T FACTORS"
T5 REM initiate
80 LET В-0
90 LET TzO
PRINT
PRINT "HOW MANY(30 MAX)?"
INPUT N
IF N»30 THEN GO TO
CLS
FOR І-1 TO N
LET Е(І)-1
PRINT І; "{#":
МЕХТ І
РКІМТ
КЕМ ргосезз сһоісе
PRINT "PICK A NUMBER"
INPUT K
CLS
IF Е(К)-0 OR КОМ OR K«2 THE
N GO TO 850
PRINT "YOU GET 4";K
REM look for factors
PRINT "I GET#";
LET С=0
FOR 1=1 TO K/?2
IF Е(І)-0 OR (K/I)*I«K THEN
GO TO 330
LET С=1
LET Е(І)-0
LET Т=Т+І
PRINT Тетте:
NEXT I
PRINT
IF C20 THEN GO TO 800
LET B=B+K
110
Program Listing
None of the REMarks are to be entered
into the ZX80; they are included to show
you the logic of the program.
If you use the Syntactic Sum < TM»
method to verify that you have entered
the program correctly, you must SAVE
the program, then NEW, then LOAD
before running. Taxman is too large to
run with the Syntactic Sum program in
memory. и"
LET Е(К) =0
PRINT
PRINT
p"
PRINT
FOR І-1 ТОМ
IF Е(І)-0 THEN GO TO 500
PRINT ии:
NEXT I
PRINT
REM check for no more factors
FOR I=4 TON
IF Е(І)-0 THEN GO TO 590
FOR К-2 TO I/2
IF NOT Е(К)-0 AND (I/K)*Kz-:I
THEN GO TO 200
NEXT K
NEXT I
REM wrapup
PRINT "DONE"
PRINT "I СЕТ":
FOR I=4 ТОМ
IF Е(І)-0 THEN GO TO 670
LET Т-Т.І
PRINT I;"£":;
NEXT I
PRINT
PRINT
GOTO 999
REM no factor found
CLS
PRINT "NO FACTOR FOR ME,"
PRINT "TRY AGAIN."
GO TO 470
REM illegal choice
PRINT "WRONG,"
GOTO 820
PRINT "FINAL SCORE-##YOU:";
В; "#МЕ:";Т
Syntactic Sum=1418
370
430
440 "SCORE- YOU:";B;"£4ME
450
470
480
490
500
510
515
520
530
540
550
580
590
595
600
610
6 30
640
650
660
670
680
690
750
795
800
810
820
8 30
815
850
860
999
47
ПЕ SOuUrceS E
Software
48
Name change:
The ZX-GROUP to:
Heuristics
25 Shute Path
Newton, MA 02159
Personal Banking System keeps track
of your personal finance and check
your bank statements also. £9.95 for
cassette and users manual; manual only
£2.00. Specify ZX80 or ZX81.
J. P. Gibbons AIB
14, Avalon Road,
Orpington, Kent, BR6 9AX
United Kingdom
Hints and Tips for the ZX81, £4.95
(plus 75p overseas); ZX61 Programmers
Toolkit for the 16K machine to do the
donkey work when writing your own
software, £8.50; Space Intruders for
16K, £6.50.
Hewson Consultants
7 Grahame Close,
Blewbury, Oxon OX11 9QE
United Kingdom
Print N Plotter, a tear-off pad of 100
sheets, 11 3/4 x 8 1/4, general planner
for ZX Graphics with 2 grids (704
character positions on 1; 2816 pixel
coordinates on 2); £3.50 incl. VAT,
post, & packing; large orders dis-
counted.
Dennis Hook
Butler, Currie & Hook.
19 Borough High Street,
London SE1 9SE
United Kingdom
2Х81 Chess, mc, 6 levels of play,
graphic display, 16К, £15.
A Lawrie (Software)
68 Bingley Road
Sunbury-on-Thames
Middlesex TW16 7RB
United Kingdom
ZX60 Cosmic Dog Fight, fast action
space game for 4K/1K and 16K (8K
available Dec. 1), $1.50 pp.
MATTEX
P.O. Box 4644
Shreveport, LA 71104-0644
Software Wanted: How and Where to
Sell Your Program, a new guide for
those who want to sell programs they
have written, intends to bring software
authors and marketers together, $25,
sold on money-back guarantee basis.
Battery Lane Publications
P.O. Box 30214
301/770-2726
e Air Traffic Control, Invaders, Phone
Book, Date 81 for ZX81 with 16K RAM.
Pack 16/81/1 £4.95.
Control Technology
39 Gloucester Road
Gee Cross, Hyde,
Cheshire SK14 5JG
Unided Kingdom
061-368-7558
ZX81 Software. Send SAE for color
catalog.
CDS Micro Systems
10 Westfield Close, Tickhill
Concaster DN11 9LA
United Kingdom
Sixtyfive ZX81 Programs, 65 ІК
programs for £4.95. Beginners Basic
Course, self teach, £10.95.
Sussex Software
Wallsend House
Pevensey Bay
Sussex
United Kingdom
Hardware
Self-Reset Power Line Interrupter,
disconnects AC power from controlled
apparatus, 4 minute time delay, auto-
matic self-reset, helps avoid wide voltage
fluctuations, intended for installations
unattended for long periods. $185.95.
Electronic Specialists, Inc.
171 S. Main St.
Natick, MA 01760
617/655-1532
RAM Packs: l6K, £42.95; 2K, £15.95;
4K, £22.95; 8K, £34.95; Keyboard (13
solder connections to PCB), £27.95.
Add £1.00 pp. Specify ZX80 ог Z X81.
dK’tronics
23 Sussex Road
Gorleston on Sea
Great Yarmouth
Norfolk
United Kingdom
(0493) 602453
24 Line I/O port, controlled using Basic,
with suitable interface circuits will
control LEDs, motors, relays, lights,
sound generators, etc., kit for £14.50,
built for £15.95. Add 40p for orders
under £10.00; 80p, over £10.00.
Redditch Electronics
21 Ferney Hill Avenue
Redditch
Worcestershire B97 4RU
United Kingdom
(0527) 61240
Full animated graphics for the ZX80
(no screen flicker); kit form, £12.95
plus VAT; for 8K ROM only. |
Comp Shop, Ltd.
14 Station Road
New Barnet
Hertfordshire, EN5 1QW
United Kingdom
FD 81 Keyboard, kit form, £18.95 plus
80p pp; built £24.95
Fuller Designs, Ltd.
Sandfield Park East
Liverpool L12 9HP |
United Kingdom "n
SYNC Magazine
creative
compating
Creative Computing-- Albert Einstein in
black on a red denim-look shirt with red
neckband and cuffs.
l'd rather be playing spacewar-- black
with white spaceships and lettering.
Computer Bum-- black design by car-
toonist Monte Woiverton on gray
denim-look shirt with black neckband
and cuffs.
Creative’s own outrageous Bionic Toad
in dark blue on a light blue shirt for
kids and adults.
Pond
j333333333333333333333233
SEREREEREEREREEEREREREREE
3
J
3
d
m
J
m
y
yl:
M:
y
y
J
d
m
d
>
m
4
Plotter display of Pi to 625 Places іп
dark brown on a tan shirt.
Give your
Не a rest!
All T-shirts are available in adult sizes
S,M,L,XL. Bionic Toad, Program Bug and
Spacewar also available in children's sizes
5(6-8), M(10-12) and L(14-16). Made in USA.
$6.00 each plus 75¢ shipping.
Specify design and size and send payment
to Creative Computing, 39 E. Hanover Ave.,
Morris Plains, NJ 07950. Orders for two or
more shirts may be charged to Visa, Master-
Card or American Express. Save time and
call toll-free 800-631-8112 (in NJ 201-540-
0445).
Beware the
Program BUG!
from Katie and the Computer
The Program Bug that terrorized Cyber-
nia in Katie and the Computer is back
on this beige t-shirt with purple design.
You can share the little monster with
your favorite kid.
Crash Cursor and Sync from the comic strip
in SYNC magazine emblazoned in white on
this black shirt.
Roll down the block with this little
black Robot Rabbit (on a bright orange
t-shirt) on your back and you сап
intimidate every carrot, radish or cuke
in your way.
Plain Talk About Business Computers
Can a Small Computer
Really Save You Time?
Time is Money
Theophrastus said time was the most
valuable thing a man could spend. Fifteen
centuries later Haliburton agreed saying,
"we reckon hours and minutes to be dollars
and cents." Today, time is more valuable
than ever— and more fleeting.
About the only way to gain time is to use
it more efficiently and effectively. That's
where we come in.
Small Business Computers —by the way,
the "small" refers to computers, not to busi-
ness— will dramatically increase your effec-
tiveness and help save you time and money.
How so?
You get flagrantly honest evaluations and
reviews of computers and software. We
dont just tell you what a program can do;
we tell you what it doesn't do, what it does
poorly, and what it should do for the price.
If advertisers dont like that, we don t want
their business, and youre better off without
them. Fortunately, most companies appre-
ciate our honesty. In fact, one of our
reviewers has gained a reputation because
of the many software houses that have
incorporated his suggestions into their
products. We re proud of that.
Plain Talk
Small Business Computers explains the
complexity of today's computerized business
world without the technical jargon and
doubletalk that may have held you back
before. In its easily comprehensible “һому-
to’ style, Small Business Computers answers
your questions while providing the infor-
mation you need to make some tough
decisions. As you select, purchase, and
install your computer system, Small Business
Computers will guide you through each
step calmly and comfortably—helping you
to evaluate your computer needs and avoid
unnecessary pitfalls. As you use your
computer, be it mini or micro, Small Business
Computers will be there to help you do so
efficiently and with confidence while inform-
ing you of the latest developments and
future possibilities of computers in busi-
ness.
For Example
You have just purchased a mailing list
program. Everything is fine until the file
has to be sorted by zip code. If the program
has that capability, all is well. If not, you
have a big problem. If you had just invested
a few hours reading Small Business Com-
puters, you would have known what func-
tions to look for before buying the program;
you would have known how to plan for
future needs. That's just one example.
Expand this concept into other areas, other
programs and systems, and you can see
what you get for your investment.
ТТТТІІІ 2220448
Added Expertise
As the newest member of the Creative
Computing family of fine computer publi-
cations, Small Business Computers will be
expanding to offer subscribers more valuable
information. than ever before. Creative
Computing editors and contributors will be
unleashing their business expertise in Small
Business Computers through articles, eval-
uations and applications of particular interest
to the business person. Creative Computing
has a reputation of editorial excellence and
integrity built on unbiased, in-depth product
evaluations; articles by top thinkers in the
field; and pragmatic, innovative applica-
tions.
One management consulting firm, for
example, used the Shell-Metzner sort
described in Creative, and saved $3000 a
month, and we still receive letters thanking
us for the hardhitting, candid, evaluation
of word processing printers we published
over a year ago, and which, incidentally,
COSt us several advertisers.
All this knowledge and experience will
now be available to business people in
Small Business Computers.
So, dont let anyone give you that old
story about how complicated and difficult
computers are. We dont buy that. Our
magazine —our whole philosophy—revolves
around the sharing of honest information.
If you don't know where to start, we'll put
you on the right track. If you're already on
the road, we'll show you the best route.
Photo courtesy of Alanthus Data Communications Corp.
For Any Size Business
Whatever your business— manufacturing
or banking, retail or research — Small Busi-
ness Computers will increase your efficiency
and help save you time and money.
Subscribe today; Small Business Com-
puters is the best consultant your business
will ever have.
Order Today
To order your subscription to Small Business
Computers send $12.00 for 1 year (6 issues).
If you prefer, call our toll free number 800-
631-8112 (in N.J. 201-540-0445) to put
your subscription on your Master Card, Visa,
or American Express card. Canadian and
other foreign surface subscriptions are
$18.00 per year and must be pre-paid. We
guarantee that you will be completely
satisfied or we will refund the remaining
portion of your subscription.
Send orders to:
Business Computers
Magazine
39 E. Hanover Ave.
Morris Plains, NJ 07950
800-631-8112
(In NJ 201-540-0445)